@pisell/pisellos 0.0.434 → 0.0.436
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/Date/index.js +14 -6
- package/dist/modules/Rules/index.d.ts +3 -1
- package/dist/modules/Rules/index.js +96 -12
- package/dist/modules/Rules/types.d.ts +6 -0
- package/dist/modules/Rules/types.js +8 -0
- package/dist/modules/Summary/utils.js +33 -26
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingByStep/index.js +5 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ShopDiscount/index.d.ts +2 -0
- package/dist/solution/ShopDiscount/index.js +9 -5
- package/lib/modules/Date/index.js +6 -0
- package/lib/modules/Rules/index.d.ts +3 -1
- package/lib/modules/Rules/index.js +41 -2
- package/lib/modules/Rules/types.d.ts +6 -0
- package/lib/modules/Rules/types.js +11 -2
- package/lib/modules/Summary/utils.js +8 -5
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingByStep/index.js +3 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ShopDiscount/index.d.ts +2 -0
- package/lib/solution/ShopDiscount/index.js +9 -4
- package/package.json +1 -1
|
@@ -85,6 +85,14 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
85
85
|
}, {
|
|
86
86
|
key: "setDateRange",
|
|
87
87
|
value: function setDateRange(dateRange) {
|
|
88
|
+
var _this2 = this;
|
|
89
|
+
// 如果 dateRange 传入的日期里没有 resource,但是本地有的,要尝试补充下
|
|
90
|
+
dateRange.forEach(function (item) {
|
|
91
|
+
var _item$resource;
|
|
92
|
+
if (!((_item$resource = item.resource) !== null && _item$resource !== void 0 && _item$resource.length)) {
|
|
93
|
+
item.resource = _this2.getResourcesListByDate(item.date);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
88
96
|
this.store.dateRange = dateRange;
|
|
89
97
|
}
|
|
90
98
|
}, {
|
|
@@ -157,10 +165,10 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
157
165
|
return n.date === item.date;
|
|
158
166
|
});
|
|
159
167
|
if (currentItemIndex !== -1) {
|
|
160
|
-
var _item$
|
|
168
|
+
var _item$resource2, _currentItem$resource3;
|
|
161
169
|
var currentItem = currentDateList[currentItemIndex];
|
|
162
170
|
// 看那一天的数据有没有相同的,把不同的资源合并进去即可
|
|
163
|
-
var newResource = (_item$
|
|
171
|
+
var newResource = (_item$resource2 = item.resource) === null || _item$resource2 === void 0 ? void 0 : _item$resource2.filter(function (n) {
|
|
164
172
|
var _currentItem$resource2;
|
|
165
173
|
return !((_currentItem$resource2 = currentItem.resource) !== null && _currentItem$resource2 !== void 0 && _currentItem$resource2.some(function (m) {
|
|
166
174
|
return m.id === n.id;
|
|
@@ -168,8 +176,8 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
168
176
|
});
|
|
169
177
|
// 如果有相同的资源,则使用 item 中的新的resource.times,而不是 currentItem 中的
|
|
170
178
|
(_currentItem$resource3 = currentItem.resource) === null || _currentItem$resource3 === void 0 || _currentItem$resource3.forEach(function (n) {
|
|
171
|
-
var _item$
|
|
172
|
-
var newResource = (_item$
|
|
179
|
+
var _item$resource3;
|
|
180
|
+
var newResource = (_item$resource3 = item.resource) === null || _item$resource3 === void 0 ? void 0 : _item$resource3.find(function (m) {
|
|
173
181
|
return m.id === n.id;
|
|
174
182
|
});
|
|
175
183
|
if (newResource) {
|
|
@@ -261,7 +269,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
261
269
|
}, {
|
|
262
270
|
key: "correctResourceTimeSlots",
|
|
263
271
|
value: function correctResourceTimeSlots(resourcesData) {
|
|
264
|
-
var
|
|
272
|
+
var _this3 = this;
|
|
265
273
|
return resourcesData.map(function (resource) {
|
|
266
274
|
// 检查资源是否有 times 数组和 start_time
|
|
267
275
|
if (!resource.times || !Array.isArray(resource.times) || !resource.start_time) {
|
|
@@ -284,7 +292,7 @@ export var DateModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
284
292
|
// 如果 start_at 早于资源的 start_time,需要修正
|
|
285
293
|
if (startAt.isBefore(resourceStartTime)) {
|
|
286
294
|
// 将 start_time 向上取整到下一个10分钟整数
|
|
287
|
-
var roundedStartTime =
|
|
295
|
+
var roundedStartTime = _this3.roundUpToNext10Minutes(resourceStartTime);
|
|
288
296
|
var roundedStartTimeDayjs = dayjs(roundedStartTime);
|
|
289
297
|
console.log("[DateModule] \u4FEE\u6B63\u65F6\u95F4\u6BB5\u5F00\u59CB\u65F6\u95F4: ".concat(timeSlot.start_at, " -> ").concat(roundedStartTime, " (\u8D44\u6E90ID: ").concat(resource.id, ", \u539F\u59CBstart_time: ").concat(resource.start_time, ")"));
|
|
290
298
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { Rules, RulesModuleAPI, DiscountResult } from './types';
|
|
3
|
+
import { Rules, RulesModuleAPI, DiscountResult, UnavailableReason } from './types';
|
|
4
4
|
import { Discount } from '../Discount/types';
|
|
5
5
|
import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
|
|
6
6
|
import { WindowPlugin } from '../../plugins';
|
|
@@ -29,7 +29,9 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
|
|
|
29
29
|
isAvailable: boolean;
|
|
30
30
|
discountList: Discount[];
|
|
31
31
|
productList: any[];
|
|
32
|
+
unavailableReason?: UnavailableReason;
|
|
32
33
|
};
|
|
34
|
+
private getUnavailableReason;
|
|
33
35
|
calcDiscount({ discountList, productList, orderTotalAmount, holders, isFormSubject, }: {
|
|
34
36
|
discountList: Discount[];
|
|
35
37
|
productList: any[];
|
|
@@ -1,6 +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
2
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
3
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
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; } } }; }
|
|
4
5
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
6
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -24,6 +25,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
24
25
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
25
26
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
26
27
|
import { BaseModule } from "../BaseModule";
|
|
28
|
+
import { UnavailableReason } from "./types";
|
|
27
29
|
import { uniqueById, getDiscountAmount, getDiscountListAmountTotal, getDiscountListAmount, filterDiscountListByBookingTime, isOrderLevelFixedAmountDiscount, calculateOrderLevelDiscountAllocation } from "../../solution/ShopDiscount/utils";
|
|
28
30
|
import { getProductOriginTotalPrice, getProductTotalPrice } from "../Cart/utils";
|
|
29
31
|
import Decimal from 'decimal.js';
|
|
@@ -150,7 +152,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
150
152
|
return {
|
|
151
153
|
isAvailable: false,
|
|
152
154
|
discountList: oldDiscountList,
|
|
153
|
-
productList: productList
|
|
155
|
+
productList: productList,
|
|
156
|
+
unavailableReason: UnavailableReason.AlreadyUsed
|
|
154
157
|
};
|
|
155
158
|
}
|
|
156
159
|
|
|
@@ -196,12 +199,93 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
});
|
|
202
|
+
|
|
203
|
+
// 如果券不可用,判断不可用原因
|
|
204
|
+
var unavailableReason;
|
|
205
|
+
if (!hasApplicableDiscount) {
|
|
206
|
+
unavailableReason = this.getUnavailableReason(newDiscountList, productList);
|
|
207
|
+
}
|
|
199
208
|
return {
|
|
200
209
|
isAvailable: hasApplicableDiscount,
|
|
201
210
|
discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
|
|
202
|
-
productList: hasApplicableDiscount ? result.productList : productList
|
|
211
|
+
productList: hasApplicableDiscount ? result.productList : productList,
|
|
212
|
+
unavailableReason: unavailableReason
|
|
203
213
|
};
|
|
204
214
|
}
|
|
215
|
+
|
|
216
|
+
// 获取券不可用的原因
|
|
217
|
+
}, {
|
|
218
|
+
key: "getUnavailableReason",
|
|
219
|
+
value: function getUnavailableReason(discountList, productList) {
|
|
220
|
+
// 检查时间限制
|
|
221
|
+
var _iterator = _createForOfIteratorHelper(discountList),
|
|
222
|
+
_step;
|
|
223
|
+
try {
|
|
224
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
225
|
+
var discount = _step.value;
|
|
226
|
+
var _iterator3 = _createForOfIteratorHelper(productList),
|
|
227
|
+
_step3;
|
|
228
|
+
try {
|
|
229
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
230
|
+
var item = _step3.value;
|
|
231
|
+
var product = this.hooks.getProduct(item);
|
|
232
|
+
var bookingTime = ((product === null || product === void 0 ? void 0 : product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss');
|
|
233
|
+
var filteredList = filterDiscountListByBookingTime([discount], bookingTime);
|
|
234
|
+
if (filteredList.length === 0) {
|
|
235
|
+
return UnavailableReason.TimeLimit;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
} catch (err) {
|
|
239
|
+
_iterator3.e(err);
|
|
240
|
+
} finally {
|
|
241
|
+
_iterator3.f();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// 检查商品适用性
|
|
246
|
+
} catch (err) {
|
|
247
|
+
_iterator.e(err);
|
|
248
|
+
} finally {
|
|
249
|
+
_iterator.f();
|
|
250
|
+
}
|
|
251
|
+
var _iterator2 = _createForOfIteratorHelper(discountList),
|
|
252
|
+
_step2;
|
|
253
|
+
try {
|
|
254
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
255
|
+
var _discount = _step2.value;
|
|
256
|
+
var limitedData = _discount.limited_relation_product_data;
|
|
257
|
+
var hasApplicableProduct = false;
|
|
258
|
+
var _iterator4 = _createForOfIteratorHelper(productList),
|
|
259
|
+
_step4;
|
|
260
|
+
try {
|
|
261
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
262
|
+
var _limitedData$product_;
|
|
263
|
+
var _item = _step4.value;
|
|
264
|
+
var _product = this.hooks.getProduct(_item);
|
|
265
|
+
if (limitedData.type === 'product_all') {
|
|
266
|
+
hasApplicableProduct = true;
|
|
267
|
+
break;
|
|
268
|
+
} else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(_product.id)) {
|
|
269
|
+
hasApplicableProduct = true;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} catch (err) {
|
|
274
|
+
_iterator4.e(err);
|
|
275
|
+
} finally {
|
|
276
|
+
_iterator4.f();
|
|
277
|
+
}
|
|
278
|
+
if (!hasApplicableProduct) {
|
|
279
|
+
return UnavailableReason.ProductNotApplicable;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
} catch (err) {
|
|
283
|
+
_iterator2.e(err);
|
|
284
|
+
} finally {
|
|
285
|
+
_iterator2.f();
|
|
286
|
+
}
|
|
287
|
+
return UnavailableReason.Unknown;
|
|
288
|
+
}
|
|
205
289
|
}, {
|
|
206
290
|
key: "calcDiscount",
|
|
207
291
|
value: function calcDiscount(_ref2, options) {
|
|
@@ -555,7 +639,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
555
639
|
|
|
556
640
|
// 辅助函数:检查商品是否对某个折扣卡可用
|
|
557
641
|
var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
|
|
558
|
-
var
|
|
642
|
+
var _product2, _product3, _product4, _flatItem$bundleItem, _flatItem$bundleItem2, _product5;
|
|
559
643
|
var product;
|
|
560
644
|
if (flatItem.type === 'main') {
|
|
561
645
|
product = flatItem.product;
|
|
@@ -574,7 +658,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
574
658
|
}
|
|
575
659
|
|
|
576
660
|
// 编辑的商品使用了优惠券不可用
|
|
577
|
-
var isAvailableProduct = flatItem.type === 'main' ? !((
|
|
661
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product2 = product) !== null && _product2 !== void 0 && _product2.booking_id && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.length && (_product4 = product) !== null && _product4 !== void 0 && (_product4 = _product4.discount_list) !== null && _product4 !== void 0 && _product4.every(function (d) {
|
|
578
662
|
return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
|
|
579
663
|
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem = flatItem.bundleItem) !== null && _flatItem$bundleItem !== void 0 && (_flatItem$bundleItem = _flatItem$bundleItem.discount_list) !== null && _flatItem$bundleItem !== void 0 && _flatItem$bundleItem.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem2 = flatItem.bundleItem) !== null && _flatItem$bundleItem2 !== void 0 && (_flatItem$bundleItem2 = _flatItem$bundleItem2.discount_list) !== null && _flatItem$bundleItem2 !== void 0 && _flatItem$bundleItem2.every(function (d) {
|
|
580
664
|
return d.id;
|
|
@@ -595,7 +679,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
595
679
|
var limitedData = discount.limited_relation_product_data;
|
|
596
680
|
|
|
597
681
|
// 时间限制检查
|
|
598
|
-
var timeLimit = !!filterDiscountListByBookingTime([discount], (((
|
|
682
|
+
var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
599
683
|
if (!timeLimit) {
|
|
600
684
|
return false;
|
|
601
685
|
}
|
|
@@ -760,7 +844,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
760
844
|
originProduct = flatItem.originProduct;
|
|
761
845
|
}
|
|
762
846
|
addModeDiscount.forEach(function (discount) {
|
|
763
|
-
var
|
|
847
|
+
var _product6, _product7, _product8, _product9, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
|
|
764
848
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
765
849
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
766
850
|
var _tempVar = (flatItem === null || flatItem === void 0 ? void 0 : flatItem.type) === 'bundle' ? flatItem === null || flatItem === void 0 ? void 0 : flatItem.parentProduct : flatItem === null || flatItem === void 0 ? void 0 : flatItem.product;
|
|
@@ -769,12 +853,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
769
853
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
770
854
|
}, holders);
|
|
771
855
|
var timeLimit = true;
|
|
772
|
-
timeLimit = !!filterDiscountListByBookingTime([discount], (((
|
|
856
|
+
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product6 = product) === null || _product6 === void 0 ? void 0 : _product6.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
773
857
|
// 是符合折扣的商品
|
|
774
858
|
var isLimitedProduct = (limitedData.type === 'product_all' && limitedData.filter !== 1 || limitedData.type === 'product_all' && limitedData.filter === 1 && !limitedData.exclude_product_ids.includes(product.id) || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
|
|
775
859
|
|
|
776
860
|
// 编辑的商品 使用了优惠券不可用
|
|
777
|
-
var isAvailableProduct = flatItem.type === 'main' ? !((
|
|
861
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product7 = product) !== null && _product7 !== void 0 && _product7.booking_id && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.length && (_product9 = product) !== null && _product9 !== void 0 && (_product9 = _product9.discount_list) !== null && _product9 !== void 0 && _product9.every(function (discount) {
|
|
778
862
|
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
779
863
|
})) : !(flatItem !== null && flatItem !== void 0 && flatItem.booking_id && !!(flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem3 = flatItem.bundleItem) !== null && _flatItem$bundleItem3 !== void 0 && (_flatItem$bundleItem3 = _flatItem$bundleItem3.discount_list) !== null && _flatItem$bundleItem3 !== void 0 && _flatItem$bundleItem3.length) && flatItem !== null && flatItem !== void 0 && (_flatItem$bundleItem4 = flatItem.bundleItem) !== null && _flatItem$bundleItem4 !== void 0 && (_flatItem$bundleItem4 = _flatItem$bundleItem4.discount_list) !== null && _flatItem$bundleItem4 !== void 0 && _flatItem$bundleItem4.every(function (discount) {
|
|
780
864
|
return discount.id;
|
|
@@ -827,7 +911,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
827
911
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
828
912
|
// 🔥 使用扁平化后的列表进行处理
|
|
829
913
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
830
|
-
var
|
|
914
|
+
var _product10, _product$discount_lis2, _product11;
|
|
831
915
|
// 获取商品数据
|
|
832
916
|
var product, originProduct;
|
|
833
917
|
if (flatItem.type === 'main') {
|
|
@@ -853,7 +937,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
853
937
|
}
|
|
854
938
|
|
|
855
939
|
// 已有优惠的商品跳过
|
|
856
|
-
if ((
|
|
940
|
+
if ((_product10 = product) !== null && _product10 !== void 0 && _product10.booking_id && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.length && (_product11 = product) !== null && _product11 !== void 0 && (_product11 = _product11.discount_list) !== null && _product11 !== void 0 && _product11.every(function (discount) {
|
|
857
941
|
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
858
942
|
})) {
|
|
859
943
|
if (flatItem.type === 'main') {
|
|
@@ -949,12 +1033,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
949
1033
|
// 如果是手动折扣,则不适用优惠券
|
|
950
1034
|
var isManualDiscount = false;
|
|
951
1035
|
if (flatItem.type === 'main') {
|
|
952
|
-
var _product$discount_lis5,
|
|
1036
|
+
var _product$discount_lis5, _product12, _product12$every;
|
|
953
1037
|
// 主商品:判断自身是否手动折扣
|
|
954
1038
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
955
1039
|
var _ref6;
|
|
956
1040
|
return !((_ref6 = item.discount_list || []) !== null && _ref6 !== void 0 && _ref6.length);
|
|
957
|
-
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((
|
|
1041
|
+
}) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product12 = product) === null || _product12 === void 0 || (_product12 = _product12.discount_list) === null || _product12 === void 0 || (_product12$every = _product12.every) === null || _product12$every === void 0 ? void 0 : _product12$every.call(_product12, function (item) {
|
|
958
1042
|
return item.type === 'product';
|
|
959
1043
|
})));
|
|
960
1044
|
} else {
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Discount } from '../Discount/types';
|
|
2
|
+
export declare enum UnavailableReason {
|
|
3
|
+
TimeLimit = "time_limit",
|
|
4
|
+
ProductNotApplicable = "product_not_applicable",
|
|
5
|
+
AlreadyUsed = "already_used",
|
|
6
|
+
Unknown = "unknown"
|
|
7
|
+
}
|
|
2
8
|
export declare enum RulesHooks {
|
|
3
9
|
OnRulesListChange = "rules:onRulesListChange",
|
|
4
10
|
OnDestroy = "rules:onDestroy"
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
// 券不可用原因枚举
|
|
2
|
+
export var UnavailableReason = /*#__PURE__*/function (UnavailableReason) {
|
|
3
|
+
UnavailableReason["TimeLimit"] = "time_limit";
|
|
4
|
+
UnavailableReason["ProductNotApplicable"] = "product_not_applicable";
|
|
5
|
+
UnavailableReason["AlreadyUsed"] = "already_used";
|
|
6
|
+
UnavailableReason["Unknown"] = "unknown";
|
|
7
|
+
return UnavailableReason;
|
|
8
|
+
}({});
|
|
1
9
|
export var RulesHooks = /*#__PURE__*/function (RulesHooks) {
|
|
2
10
|
RulesHooks["OnRulesListChange"] = "rules:onRulesListChange";
|
|
3
11
|
RulesHooks["OnDestroy"] = "rules:onDestroy";
|
|
@@ -336,7 +336,6 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
|
|
|
336
336
|
var bundlePreciseTax = new Decimal(0);
|
|
337
337
|
var bundleRoundedOriginTax = new Decimal(0);
|
|
338
338
|
var bundleRoundedTax = new Decimal(0);
|
|
339
|
-
debugger;
|
|
340
339
|
if (Array.isArray(item === null || item === void 0 ? void 0 : item.bundle)) {
|
|
341
340
|
var _iterator3 = _createForOfIteratorHelper(item === null || item === void 0 ? void 0 : item.bundle),
|
|
342
341
|
_step3;
|
|
@@ -346,7 +345,7 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
|
|
|
346
345
|
// 只处理原价的子商品
|
|
347
346
|
if (getBundleItemIsOriginalPrice(bundleItem)) {
|
|
348
347
|
var _ref3, _bundleItem$bundle_se;
|
|
349
|
-
var bundleQuantity = new Decimal(bundleItem.quantity || 1);
|
|
348
|
+
var bundleQuantity = new Decimal(bundleItem.num || bundleItem.quantity || 1);
|
|
350
349
|
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);
|
|
351
350
|
|
|
352
351
|
// 计算原始税费(折扣前)- 单个商品(精确值)
|
|
@@ -474,14 +473,18 @@ var processItemsTax = function processItemsTax(items, _ref2, options) {
|
|
|
474
473
|
* @returns 精确的税费值(Decimal类型)
|
|
475
474
|
*/
|
|
476
475
|
var getProductItemTax = function getProductItemTax(item, state, options) {
|
|
477
|
-
var _bookingDetail$tax_ra,
|
|
476
|
+
var _ref4, _item$quantity, _bookingDetail$tax_ra, _ref5, _bookingDetail$is_pri;
|
|
478
477
|
var bookingDetail = state.bookingDetail;
|
|
479
478
|
var tax_rate = options.tax_rate,
|
|
480
479
|
is_price_include_tax = options.is_price_include_tax;
|
|
481
480
|
|
|
482
481
|
// 折扣后的金额 = 商品金额 - 商品折扣
|
|
483
482
|
var productDiscountPrice = new Decimal(item.total || 0);
|
|
484
|
-
|
|
483
|
+
/**
|
|
484
|
+
* 注意:该函数被多处以“单件税费”方式调用(调用方会显式传入 quantity: 1),
|
|
485
|
+
* 因此这里必须优先使用 `item.quantity`,否则会出现数量被重复相乘(外层再乘一次 num)的情况。
|
|
486
|
+
*/
|
|
487
|
+
var quantity = new Decimal((_ref4 = (_item$quantity = item.quantity) !== null && _item$quantity !== void 0 ? _item$quantity : item.num) !== null && _ref4 !== void 0 ? _ref4 : 1);
|
|
485
488
|
|
|
486
489
|
// 如果商品金额小于或等于0,不计算税费
|
|
487
490
|
if (productDiscountPrice.lte(0)) {
|
|
@@ -491,7 +494,7 @@ var getProductItemTax = function getProductItemTax(item, state, options) {
|
|
|
491
494
|
// 优先从 bookingDetail 取税率和是否含税设置,取不到则从 options 中取(兼容新增模式)
|
|
492
495
|
// 注意:bookingDetail中的tax_rate不需要除以100,options 中的tax_rate需要除以100
|
|
493
496
|
var currentTaxRate = new Decimal((_bookingDetail$tax_ra = bookingDetail === null || bookingDetail === void 0 ? void 0 : bookingDetail.tax_rate) !== null && _bookingDetail$tax_ra !== void 0 ? _bookingDetail$tax_ra : tax_rate ? tax_rate / 100 : 0);
|
|
494
|
-
var currentIsPriceIncludeTax = (
|
|
497
|
+
var currentIsPriceIncludeTax = (_ref5 = (_bookingDetail$is_pri = bookingDetail === null || bookingDetail === void 0 ? void 0 : bookingDetail.is_price_include_tax) !== null && _bookingDetail$is_pri !== void 0 ? _bookingDetail$is_pri : is_price_include_tax) !== null && _ref5 !== void 0 ? _ref5 : 0;
|
|
495
498
|
var singleItemTax = new Decimal(0);
|
|
496
499
|
|
|
497
500
|
// 计算单个商品税费, 一次性商品 is_charge_tax 可能为空
|
|
@@ -567,9 +570,9 @@ export var calculateTaxFee = function calculateTaxFee(shopInfo, items) {
|
|
|
567
570
|
if (!(items !== null && items !== void 0 && items.length)) {
|
|
568
571
|
return '0.00';
|
|
569
572
|
}
|
|
570
|
-
var
|
|
571
|
-
is_price_include_tax =
|
|
572
|
-
tax_rate =
|
|
573
|
+
var _ref6 = shopInfo || {},
|
|
574
|
+
is_price_include_tax = _ref6.is_price_include_tax,
|
|
575
|
+
tax_rate = _ref6.tax_rate;
|
|
573
576
|
var totalTaxFee = items.reduce(function (sum, item) {
|
|
574
577
|
var cartItemTotalPrice = new Decimal(item.summaryTotal || 0);
|
|
575
578
|
var taxRate = new Decimal(tax_rate || 0).div(100);
|
|
@@ -631,9 +634,9 @@ export var calculateDeposit = function calculateDeposit(items) {
|
|
|
631
634
|
* @param options.isEdit 是否处于“编辑中”。`false` 时会优先走后端金额直取逻辑(若存在)
|
|
632
635
|
* @returns 订单附加费金额(number,金额单位与商品价格一致)
|
|
633
636
|
*/
|
|
634
|
-
export var getSurchargeAmount = function getSurchargeAmount(
|
|
635
|
-
var bookingDetail =
|
|
636
|
-
bookingId =
|
|
637
|
+
export var getSurchargeAmount = function getSurchargeAmount(_ref7, surcharge, options) {
|
|
638
|
+
var bookingDetail = _ref7.bookingDetail,
|
|
639
|
+
bookingId = _ref7.bookingId;
|
|
637
640
|
var isEdit = options.isEdit;
|
|
638
641
|
// 订单未变更过
|
|
639
642
|
if (!isEdit) {
|
|
@@ -678,9 +681,13 @@ var getDiscountAmount = function getDiscountAmount(discounts) {
|
|
|
678
681
|
* 获取主商品加价减价后的总价 (主商品价格 + 子商品加价减价)
|
|
679
682
|
*/
|
|
680
683
|
var getMainProductTotal = function getMainProductTotal(item) {
|
|
681
|
-
var
|
|
682
|
-
var total = new Decimal((
|
|
683
|
-
var
|
|
684
|
+
var _ref8, _ref9, _item$main_product_se, _item$metadata, _item$_origin3, _item$_originData;
|
|
685
|
+
var total = new Decimal((_ref8 = (_ref9 = (_item$main_product_se = item === null || item === void 0 ? void 0 : item.main_product_selling_price) !== null && _item$main_product_se !== void 0 ? _item$main_product_se : item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.main_product_selling_price) !== null && _ref9 !== void 0 ? _ref9 : item.price) !== null && _ref8 !== void 0 ? _ref8 : 0);
|
|
686
|
+
var discount = (item === null || item === void 0 || (_item$_origin3 = item._origin) === null || _item$_origin3 === void 0 || (_item$_origin3 = _item$_origin3.product) === null || _item$_origin3 === void 0 ? void 0 : _item$_origin3.discount_list) || (item === null || item === void 0 || (_item$_originData = item._originData) === null || _item$_originData === void 0 || (_item$_originData = _item$_originData.product) === null || _item$_originData === void 0 || (_item$_originData = _item$_originData.discount_list) === null || _item$_originData === void 0 ? void 0 : _item$_originData.filter(function (item) {
|
|
687
|
+
var _item$metadata2;
|
|
688
|
+
return !(item !== null && item !== void 0 && (_item$metadata2 = item.metadata) !== null && _item$metadata2 !== void 0 && _item$metadata2.custom_product_bundle_map_id);
|
|
689
|
+
})) || [];
|
|
690
|
+
var mainProductDiscountAmount = getDiscountAmount(discount);
|
|
684
691
|
total = total.minus(mainProductDiscountAmount);
|
|
685
692
|
|
|
686
693
|
// 单规格
|
|
@@ -695,11 +702,11 @@ var getMainProductTotal = function getMainProductTotal(item) {
|
|
|
695
702
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
696
703
|
var bundleItem = _step4.value;
|
|
697
704
|
if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
|
|
698
|
-
var
|
|
705
|
+
var _ref10, _bundleItem$bundle_se2;
|
|
699
706
|
// 子商品折扣金额
|
|
700
707
|
var discountAmount = getDiscountAmount(bundleItem.discount_list);
|
|
701
708
|
// 子商品价格
|
|
702
|
-
var bundleItemPrice = new Decimal((
|
|
709
|
+
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);
|
|
703
710
|
// todo: 套餐子商品后不需要处理 子商品价格 - 子商品折扣金额
|
|
704
711
|
var bundleItemTotal = bundleItemPrice.minus(discountAmount);
|
|
705
712
|
total = total.add(bundleItemTotal);
|
|
@@ -822,11 +829,11 @@ var isProductMatchSurchargeCondition = function isProductMatchSurchargeCondition
|
|
|
822
829
|
* @param options.scheduleById schedule 映射表:`{ [scheduleId]: schedule }`(用于根据配置的 `available_schedule_ids` 做日程匹配)
|
|
823
830
|
* @returns 附加费列表(仅返回金额 > 0 的项)
|
|
824
831
|
*/
|
|
825
|
-
export var getSurcharge = function getSurcharge(
|
|
826
|
-
var service =
|
|
827
|
-
addons =
|
|
828
|
-
bookingDetail =
|
|
829
|
-
bookingId =
|
|
832
|
+
export var getSurcharge = function getSurcharge(_ref11, options) {
|
|
833
|
+
var service = _ref11.service,
|
|
834
|
+
addons = _ref11.addons,
|
|
835
|
+
bookingDetail = _ref11.bookingDetail,
|
|
836
|
+
bookingId = _ref11.bookingId;
|
|
830
837
|
var isEdit = options.isEdit,
|
|
831
838
|
isInScheduleByDate = options.isInScheduleByDate,
|
|
832
839
|
surcharge_list = options.surcharge_list,
|
|
@@ -938,11 +945,11 @@ export var getSurcharge = function getSurcharge(_ref10, options) {
|
|
|
938
945
|
scheduleById: scheduleById || {},
|
|
939
946
|
isInScheduleByDate: isInScheduleByDate
|
|
940
947
|
})) {
|
|
941
|
-
var
|
|
948
|
+
var _ref12, _bundleItem$bundle_se3;
|
|
942
949
|
var _mainQuantity = item.num || 1;
|
|
943
950
|
matchedItems.push({
|
|
944
951
|
isMain: false,
|
|
945
|
-
total: Number((
|
|
952
|
+
total: Number((_ref12 = (_bundleItem$bundle_se3 = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se3 !== void 0 ? _bundleItem$bundle_se3 : bundleItem.price) !== null && _ref12 !== void 0 ? _ref12 : 0),
|
|
946
953
|
quantity: bundleItem.num || bundleItem.quantity || 1,
|
|
947
954
|
item: bundleItem,
|
|
948
955
|
mainQuantity: _mainQuantity // 子商品的mainQuantity是所属主商品的quantity
|
|
@@ -1156,9 +1163,9 @@ export var getSurcharge = function getSurcharge(_ref10, options) {
|
|
|
1156
1163
|
}
|
|
1157
1164
|
return surchargeWithAmount;
|
|
1158
1165
|
};
|
|
1159
|
-
function resetItemsSurchargeSideEffects(
|
|
1160
|
-
var service =
|
|
1161
|
-
addons =
|
|
1166
|
+
function resetItemsSurchargeSideEffects(_ref13) {
|
|
1167
|
+
var service = _ref13.service,
|
|
1168
|
+
addons = _ref13.addons;
|
|
1162
1169
|
var resetItem = function resetItem(item) {
|
|
1163
1170
|
if (!item) return;
|
|
1164
1171
|
item.surcharge_fee = 0;
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 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<"
|
|
361
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
362
362
|
/**
|
|
363
363
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
364
364
|
*
|
|
@@ -1163,7 +1163,6 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
1163
1163
|
var productData = _objectSpread(_objectSpread({}, origin), {}, {
|
|
1164
1164
|
product_variant_id: product_variant_id
|
|
1165
1165
|
});
|
|
1166
|
-
debugger;
|
|
1167
1166
|
// 保护,如果进来的是 session 商品,则必须要有 date 和时间片,否则不允许添加
|
|
1168
1167
|
if (isSessionProduct(productData)) {
|
|
1169
1168
|
if (!date || !date.startTime || !date.endTime) {
|
|
@@ -2138,6 +2137,11 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
2138
2137
|
}
|
|
2139
2138
|
});
|
|
2140
2139
|
}
|
|
2140
|
+
|
|
2141
|
+
// 如果依然 resources 空的,则证明他是切换日期了,此时直接从 date 模块里取
|
|
2142
|
+
if (resources.length === 0) {
|
|
2143
|
+
resources.push.apply(resources, _toConsumableArray(this.store.date.getResourcesListByDate(dateRange[0].date) || []));
|
|
2144
|
+
}
|
|
2141
2145
|
var resourcesMap = getResourcesMap(resources);
|
|
2142
2146
|
var duration = 0;
|
|
2143
2147
|
// duration = 不同账号的最长时间
|
|
@@ -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, "
|
|
126
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
127
127
|
/**
|
|
128
128
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
129
129
|
* @returns 客户状态
|
|
@@ -2,6 +2,7 @@ import { Module, PisellCore } from '../../types';
|
|
|
2
2
|
import { BaseModule } from '../../modules/BaseModule';
|
|
3
3
|
import { Customer, SetDiscountSelectedParams } from './types';
|
|
4
4
|
import { Discount } from '../../modules/Discount/types';
|
|
5
|
+
import { UnavailableReason } from '../../modules/Rules/types';
|
|
5
6
|
export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
6
7
|
protected defaultName: string;
|
|
7
8
|
protected defaultVersion: string;
|
|
@@ -43,6 +44,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
43
44
|
productList: Record<string, any>[];
|
|
44
45
|
discountList: Discount[];
|
|
45
46
|
type: "server" | "clientCalc";
|
|
47
|
+
unavailableReason?: UnavailableReason;
|
|
46
48
|
}>;
|
|
47
49
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
48
50
|
private getCustomer;
|
|
@@ -28,6 +28,7 @@ import { BaseModule } from "../../modules/BaseModule";
|
|
|
28
28
|
import { DiscountModule } from "../../modules/Discount";
|
|
29
29
|
import { RulesModule } from "../../modules/Rules";
|
|
30
30
|
import { filterDiscountListByBookingTime as _filterDiscountListByBookingTime, isAllNormalProduct } from "./utils";
|
|
31
|
+
import { UnavailableReason } from "../../modules/Rules/types";
|
|
31
32
|
import Decimal from 'decimal.js';
|
|
32
33
|
import { isBoolean } from 'lodash-es';
|
|
33
34
|
export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
@@ -398,7 +399,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
398
399
|
key: "scanCode",
|
|
399
400
|
value: function () {
|
|
400
401
|
var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
|
|
401
|
-
var _this$store$discount3, _this$store$bookingSu2, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, _this$options$otherPa6;
|
|
402
|
+
var _this$store$discount3, _this$store$bookingSu2, resultDiscountList, rulesModule, withScanList, currentSelectedDiscountList, _ref2, newProductList, newDiscountList, isAvailable, unavailableReason, _this$options$otherPa6;
|
|
402
403
|
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
403
404
|
while (1) switch (_context5.prev = _context5.next) {
|
|
404
405
|
case 0:
|
|
@@ -423,7 +424,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
423
424
|
type: "clientCalc",
|
|
424
425
|
isAvailable: false,
|
|
425
426
|
productList: this.store.productList || [],
|
|
426
|
-
discountList: this.getDiscountList()
|
|
427
|
+
discountList: this.getDiscountList(),
|
|
428
|
+
unavailableReason: UnavailableReason.Unknown
|
|
427
429
|
});
|
|
428
430
|
case 10:
|
|
429
431
|
if (resultDiscountList.length) {
|
|
@@ -471,7 +473,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
471
473
|
isAvailable: false,
|
|
472
474
|
productList: this.store.productList || [],
|
|
473
475
|
discountList: this.getDiscountList()
|
|
474
|
-
}, newProductList = _ref2.productList, newDiscountList = _ref2.discountList, isAvailable = _ref2.isAvailable;
|
|
476
|
+
}, newProductList = _ref2.productList, newDiscountList = _ref2.discountList, isAvailable = _ref2.isAvailable, unavailableReason = _ref2.unavailableReason;
|
|
475
477
|
if (!isAvailable) {
|
|
476
478
|
_context5.next = 24;
|
|
477
479
|
break;
|
|
@@ -490,7 +492,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
490
492
|
type: "clientCalc",
|
|
491
493
|
isAvailable: isAvailable || false,
|
|
492
494
|
productList: newProductList || this.store.productList || [],
|
|
493
|
-
discountList: newDiscountList || this.getDiscountList()
|
|
495
|
+
discountList: newDiscountList || this.getDiscountList(),
|
|
496
|
+
unavailableReason: unavailableReason
|
|
494
497
|
});
|
|
495
498
|
case 27:
|
|
496
499
|
_context5.prev = 27;
|
|
@@ -500,7 +503,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
|
|
|
500
503
|
type: "clientCalc",
|
|
501
504
|
isAvailable: false,
|
|
502
505
|
productList: this.store.productList || [],
|
|
503
|
-
discountList: this.getDiscountList()
|
|
506
|
+
discountList: this.getDiscountList(),
|
|
507
|
+
unavailableReason: UnavailableReason.Unknown
|
|
504
508
|
});
|
|
505
509
|
case 31:
|
|
506
510
|
case "end":
|
|
@@ -64,6 +64,12 @@ var DateModule = class extends import_BaseModule.BaseModule {
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
setDateRange(dateRange) {
|
|
67
|
+
dateRange.forEach((item) => {
|
|
68
|
+
var _a;
|
|
69
|
+
if (!((_a = item.resource) == null ? void 0 : _a.length)) {
|
|
70
|
+
item.resource = this.getResourcesListByDate(item.date);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
67
73
|
this.store.dateRange = dateRange;
|
|
68
74
|
}
|
|
69
75
|
getDateRange() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Module, PisellCore, ModuleOptions } from '../../types';
|
|
2
2
|
import { BaseModule } from '../BaseModule';
|
|
3
|
-
import { Rules, RulesModuleAPI, DiscountResult } from './types';
|
|
3
|
+
import { Rules, RulesModuleAPI, DiscountResult, UnavailableReason } from './types';
|
|
4
4
|
import { Discount } from '../Discount/types';
|
|
5
5
|
import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
|
|
6
6
|
import { WindowPlugin } from '../../plugins';
|
|
@@ -29,7 +29,9 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
|
|
|
29
29
|
isAvailable: boolean;
|
|
30
30
|
discountList: Discount[];
|
|
31
31
|
productList: any[];
|
|
32
|
+
unavailableReason?: UnavailableReason;
|
|
32
33
|
};
|
|
34
|
+
private getUnavailableReason;
|
|
33
35
|
calcDiscount({ discountList, productList, orderTotalAmount, holders, isFormSubject, }: {
|
|
34
36
|
discountList: Discount[];
|
|
35
37
|
productList: any[];
|
|
@@ -33,6 +33,7 @@ __export(Rules_exports, {
|
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(Rules_exports);
|
|
35
35
|
var import_BaseModule = require("../BaseModule");
|
|
36
|
+
var import_types = require("./types");
|
|
36
37
|
var import_utils = require("../../solution/ShopDiscount/utils");
|
|
37
38
|
var import_utils2 = require("../Cart/utils");
|
|
38
39
|
var import_decimal = __toESM(require("decimal.js"));
|
|
@@ -99,7 +100,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
99
100
|
return {
|
|
100
101
|
isAvailable: false,
|
|
101
102
|
discountList: oldDiscountList,
|
|
102
|
-
productList
|
|
103
|
+
productList,
|
|
104
|
+
unavailableReason: import_types.UnavailableReason.AlreadyUsed
|
|
103
105
|
};
|
|
104
106
|
}
|
|
105
107
|
const filteredOldDiscountList = oldDiscountList.filter(
|
|
@@ -141,12 +143,49 @@ var RulesModule = class extends import_BaseModule.BaseModule {
|
|
|
141
143
|
}
|
|
142
144
|
}
|
|
143
145
|
});
|
|
146
|
+
let unavailableReason;
|
|
147
|
+
if (!hasApplicableDiscount) {
|
|
148
|
+
unavailableReason = this.getUnavailableReason(newDiscountList, productList);
|
|
149
|
+
}
|
|
144
150
|
return {
|
|
145
151
|
isAvailable: hasApplicableDiscount,
|
|
146
152
|
discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
|
|
147
|
-
productList: hasApplicableDiscount ? result.productList : productList
|
|
153
|
+
productList: hasApplicableDiscount ? result.productList : productList,
|
|
154
|
+
unavailableReason
|
|
148
155
|
};
|
|
149
156
|
}
|
|
157
|
+
// 获取券不可用的原因
|
|
158
|
+
getUnavailableReason(discountList, productList) {
|
|
159
|
+
var _a;
|
|
160
|
+
for (const discount of discountList) {
|
|
161
|
+
for (const item of productList) {
|
|
162
|
+
const product = this.hooks.getProduct(item);
|
|
163
|
+
const bookingTime = ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss");
|
|
164
|
+
const filteredList = (0, import_utils.filterDiscountListByBookingTime)([discount], bookingTime);
|
|
165
|
+
if (filteredList.length === 0) {
|
|
166
|
+
return import_types.UnavailableReason.TimeLimit;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
for (const discount of discountList) {
|
|
171
|
+
const limitedData = discount.limited_relation_product_data;
|
|
172
|
+
let hasApplicableProduct = false;
|
|
173
|
+
for (const item of productList) {
|
|
174
|
+
const product = this.hooks.getProduct(item);
|
|
175
|
+
if (limitedData.type === "product_all") {
|
|
176
|
+
hasApplicableProduct = true;
|
|
177
|
+
break;
|
|
178
|
+
} else if ((_a = limitedData.product_ids) == null ? void 0 : _a.includes(product.id)) {
|
|
179
|
+
hasApplicableProduct = true;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
if (!hasApplicableProduct) {
|
|
184
|
+
return import_types.UnavailableReason.ProductNotApplicable;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return import_types.UnavailableReason.Unknown;
|
|
188
|
+
}
|
|
150
189
|
calcDiscount({
|
|
151
190
|
discountList,
|
|
152
191
|
productList,
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Discount } from '../Discount/types';
|
|
2
|
+
export declare enum UnavailableReason {
|
|
3
|
+
TimeLimit = "time_limit",
|
|
4
|
+
ProductNotApplicable = "product_not_applicable",
|
|
5
|
+
AlreadyUsed = "already_used",
|
|
6
|
+
Unknown = "unknown"
|
|
7
|
+
}
|
|
2
8
|
export declare enum RulesHooks {
|
|
3
9
|
OnRulesListChange = "rules:onRulesListChange",
|
|
4
10
|
OnDestroy = "rules:onDestroy"
|
|
@@ -19,9 +19,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
// src/modules/Rules/types.ts
|
|
20
20
|
var types_exports = {};
|
|
21
21
|
__export(types_exports, {
|
|
22
|
-
RulesHooks: () => RulesHooks
|
|
22
|
+
RulesHooks: () => RulesHooks,
|
|
23
|
+
UnavailableReason: () => UnavailableReason
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(types_exports);
|
|
26
|
+
var UnavailableReason = /* @__PURE__ */ ((UnavailableReason2) => {
|
|
27
|
+
UnavailableReason2["TimeLimit"] = "time_limit";
|
|
28
|
+
UnavailableReason2["ProductNotApplicable"] = "product_not_applicable";
|
|
29
|
+
UnavailableReason2["AlreadyUsed"] = "already_used";
|
|
30
|
+
UnavailableReason2["Unknown"] = "unknown";
|
|
31
|
+
return UnavailableReason2;
|
|
32
|
+
})(UnavailableReason || {});
|
|
25
33
|
var RulesHooks = /* @__PURE__ */ ((RulesHooks2) => {
|
|
26
34
|
RulesHooks2["OnRulesListChange"] = "rules:onRulesListChange";
|
|
27
35
|
RulesHooks2["OnDestroy"] = "rules:onDestroy";
|
|
@@ -29,5 +37,6 @@ var RulesHooks = /* @__PURE__ */ ((RulesHooks2) => {
|
|
|
29
37
|
})(RulesHooks || {});
|
|
30
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
39
|
0 && (module.exports = {
|
|
32
|
-
RulesHooks
|
|
40
|
+
RulesHooks,
|
|
41
|
+
UnavailableReason
|
|
33
42
|
});
|
|
@@ -212,11 +212,10 @@ var processItemsTax = (items, { bookingDetail, bookingId }, options) => {
|
|
|
212
212
|
let bundlePreciseTax = new import_decimal.default(0);
|
|
213
213
|
let bundleRoundedOriginTax = new import_decimal.default(0);
|
|
214
214
|
let bundleRoundedTax = new import_decimal.default(0);
|
|
215
|
-
debugger;
|
|
216
215
|
if (Array.isArray(item == null ? void 0 : item.bundle)) {
|
|
217
216
|
for (let bundleItem of item == null ? void 0 : item.bundle) {
|
|
218
217
|
if (getBundleItemIsOriginalPrice(bundleItem)) {
|
|
219
|
-
const bundleQuantity = new import_decimal.default(bundleItem.quantity || 1);
|
|
218
|
+
const bundleQuantity = new import_decimal.default(bundleItem.num || bundleItem.quantity || 1);
|
|
220
219
|
const bundleUnitPrice = new import_decimal.default(
|
|
221
220
|
bundleItem.bundle_selling_price ?? bundleItem.price ?? 0
|
|
222
221
|
);
|
|
@@ -294,7 +293,7 @@ var getProductItemTax = (item, state, options) => {
|
|
|
294
293
|
const { bookingDetail } = state;
|
|
295
294
|
const { tax_rate, is_price_include_tax } = options;
|
|
296
295
|
const productDiscountPrice = new import_decimal.default(item.total || 0);
|
|
297
|
-
const quantity = new import_decimal.default(item.num
|
|
296
|
+
const quantity = new import_decimal.default(item.quantity ?? item.num ?? 1);
|
|
298
297
|
if (productDiscountPrice.lte(0)) {
|
|
299
298
|
return new import_decimal.default(0);
|
|
300
299
|
}
|
|
@@ -409,9 +408,13 @@ var getDiscountAmount = (discounts) => {
|
|
|
409
408
|
}, new import_decimal.default(0)).toNumber();
|
|
410
409
|
};
|
|
411
410
|
var getMainProductTotal = (item) => {
|
|
412
|
-
var _a, _b, _c, _d;
|
|
411
|
+
var _a, _b, _c, _d, _e, _f;
|
|
413
412
|
let total = new import_decimal.default((item == null ? void 0 : item.main_product_selling_price) ?? ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.main_product_selling_price) ?? item.price ?? 0);
|
|
414
|
-
const
|
|
413
|
+
const discount = ((_c = (_b = item == null ? void 0 : item._origin) == null ? void 0 : _b.product) == null ? void 0 : _c.discount_list) || ((_f = (_e = (_d = item == null ? void 0 : item._originData) == null ? void 0 : _d.product) == null ? void 0 : _e.discount_list) == null ? void 0 : _f.filter((item2) => {
|
|
414
|
+
var _a2;
|
|
415
|
+
return !((_a2 = item2 == null ? void 0 : item2.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
|
|
416
|
+
})) || [];
|
|
417
|
+
const mainProductDiscountAmount = getDiscountAmount(discount);
|
|
415
418
|
total = total.minus(mainProductDiscountAmount);
|
|
416
419
|
if ((item == null ? void 0 : item.option) && Array.isArray(item == null ? void 0 : item.option)) {
|
|
417
420
|
total = total.add(item == null ? void 0 : item.option.reduce((t, option) => {
|
|
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
311
311
|
date: string;
|
|
312
312
|
status: string;
|
|
313
313
|
week: string;
|
|
314
|
-
weekNum: 0 |
|
|
314
|
+
weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 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<"
|
|
361
|
+
getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
|
|
362
362
|
/**
|
|
363
363
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
364
364
|
*
|
|
@@ -608,7 +608,6 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
608
608
|
quantity = 1
|
|
609
609
|
} = product || {};
|
|
610
610
|
const productData = { ...origin, product_variant_id };
|
|
611
|
-
debugger;
|
|
612
611
|
if ((0, import_products.isSessionProduct)(productData)) {
|
|
613
612
|
if (!date || !date.startTime || !date.endTime) {
|
|
614
613
|
return { success: false, errorCode: "date_or_time_required" };
|
|
@@ -1464,6 +1463,9 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
|
|
|
1464
1463
|
}
|
|
1465
1464
|
});
|
|
1466
1465
|
}
|
|
1466
|
+
if (resources.length === 0) {
|
|
1467
|
+
resources.push(...this.store.date.getResourcesListByDate(dateRange[0].date) || []);
|
|
1468
|
+
}
|
|
1467
1469
|
const resourcesMap = (0, import_utils2.getResourcesMap)(resources);
|
|
1468
1470
|
let duration = 0;
|
|
1469
1471
|
const accountList = this.store.accountList.getAccounts();
|
|
@@ -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, "
|
|
126
|
+
getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
|
|
127
127
|
/**
|
|
128
128
|
* 获取客户列表状态(包含滚动加载相关状态)
|
|
129
129
|
* @returns 客户状态
|
|
@@ -2,6 +2,7 @@ import { Module, PisellCore } from '../../types';
|
|
|
2
2
|
import { BaseModule } from '../../modules/BaseModule';
|
|
3
3
|
import { Customer, SetDiscountSelectedParams } from './types';
|
|
4
4
|
import { Discount } from '../../modules/Discount/types';
|
|
5
|
+
import { UnavailableReason } from '../../modules/Rules/types';
|
|
5
6
|
export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
6
7
|
protected defaultName: string;
|
|
7
8
|
protected defaultVersion: string;
|
|
@@ -43,6 +44,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
|
|
|
43
44
|
productList: Record<string, any>[];
|
|
44
45
|
discountList: Discount[];
|
|
45
46
|
type: "server" | "clientCalc";
|
|
47
|
+
unavailableReason?: UnavailableReason;
|
|
46
48
|
}>;
|
|
47
49
|
calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
|
|
48
50
|
private getCustomer;
|
|
@@ -37,6 +37,7 @@ var import_BaseModule = require("../../modules/BaseModule");
|
|
|
37
37
|
var import_Discount = require("../../modules/Discount");
|
|
38
38
|
var import_Rules = require("../../modules/Rules");
|
|
39
39
|
var import_utils = require("./utils");
|
|
40
|
+
var import_types = require("../../modules/Rules/types");
|
|
40
41
|
var import_decimal = __toESM(require("decimal.js"));
|
|
41
42
|
var import_lodash_es = require("lodash-es");
|
|
42
43
|
var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
@@ -274,7 +275,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
274
275
|
type: "clientCalc",
|
|
275
276
|
isAvailable: false,
|
|
276
277
|
productList: this.store.productList || [],
|
|
277
|
-
discountList: this.getDiscountList()
|
|
278
|
+
discountList: this.getDiscountList(),
|
|
279
|
+
unavailableReason: import_types.UnavailableReason.Unknown
|
|
278
280
|
};
|
|
279
281
|
}
|
|
280
282
|
if (!resultDiscountList.length) {
|
|
@@ -303,7 +305,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
303
305
|
const {
|
|
304
306
|
productList: newProductList,
|
|
305
307
|
discountList: newDiscountList,
|
|
306
|
-
isAvailable
|
|
308
|
+
isAvailable,
|
|
309
|
+
unavailableReason
|
|
307
310
|
} = rulesModule.isDiscountListAvailable({
|
|
308
311
|
productList: this.store.productList || [],
|
|
309
312
|
oldDiscountList: this.getDiscountList(),
|
|
@@ -330,7 +333,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
330
333
|
type: "clientCalc",
|
|
331
334
|
isAvailable: isAvailable || false,
|
|
332
335
|
productList: newProductList || this.store.productList || [],
|
|
333
|
-
discountList: newDiscountList || this.getDiscountList()
|
|
336
|
+
discountList: newDiscountList || this.getDiscountList(),
|
|
337
|
+
unavailableReason
|
|
334
338
|
};
|
|
335
339
|
} catch (error) {
|
|
336
340
|
console.error("[ShopDiscount] 扫码出错:", error);
|
|
@@ -338,7 +342,8 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
|
|
|
338
342
|
type: "clientCalc",
|
|
339
343
|
isAvailable: false,
|
|
340
344
|
productList: this.store.productList || [],
|
|
341
|
-
discountList: this.getDiscountList()
|
|
345
|
+
discountList: this.getDiscountList(),
|
|
346
|
+
unavailableReason: import_types.UnavailableReason.Unknown
|
|
342
347
|
};
|
|
343
348
|
}
|
|
344
349
|
}
|