@pisell/pisellos 0.10.2 → 0.10.4
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/core/index.d.ts +2 -0
- package/dist/core/index.js +7 -0
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
- package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
- package/dist/model/strategy/adapter/promotion/examples.js +99 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/dist/model/strategy/adapter/promotion/type.js +45 -0
- package/dist/modules/BaseModule.d.ts +1 -0
- package/dist/modules/BaseModule.js +24 -28
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
- package/dist/modules/OpenData/index.d.ts +2 -0
- package/dist/modules/OpenData/index.js +8 -0
- package/dist/modules/Order/index.d.ts +41 -10
- package/dist/modules/Order/index.js +943 -546
- package/dist/modules/Order/payment-utils.d.ts +26 -0
- package/dist/modules/Order/payment-utils.js +225 -0
- package/dist/modules/Order/types.d.ts +43 -2
- package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
- package/dist/modules/Order/utils.js +10 -6
- package/dist/modules/Payment/index.d.ts +2 -0
- package/dist/modules/Payment/index.js +79 -50
- package/dist/modules/Payment/types.d.ts +107 -28
- package/dist/modules/Payment/types.js +20 -3
- package/dist/modules/Payment/walletpass.d.ts +38 -1
- package/dist/modules/Payment/walletpass.js +917 -114
- package/dist/modules/ProductList/index.js +1 -1
- package/dist/modules/Rules/index.d.ts +3 -0
- package/dist/modules/Rules/index.js +130 -99
- package/dist/server/index.d.ts +16 -0
- package/dist/server/index.js +2084 -1188
- package/dist/server/modules/index.d.ts +1 -1
- package/dist/server/modules/order/index.d.ts +70 -4
- package/dist/server/modules/order/index.js +1816 -728
- package/dist/server/modules/order/types.d.ts +25 -3
- package/dist/server/modules/order/types.js +7 -1
- package/dist/solution/BaseSales/index.d.ts +114 -14
- package/dist/solution/BaseSales/index.js +1848 -478
- package/dist/solution/BaseSales/types.d.ts +55 -1
- package/dist/solution/BaseSales/types.js +2 -1
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
- package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +8 -16
- package/dist/solution/BookingTicket/index.js +138 -52
- package/dist/solution/BookingTicket/types.d.ts +1 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
- package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
- package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
- package/dist/solution/Sales/index.d.ts +1 -0
- package/dist/solution/Sales/index.js +10 -2
- package/dist/solution/ScanOrder/index.js +31 -20
- package/dist/solution/UnifiedBookingSales/index.d.ts +3 -0
- package/dist/solution/UnifiedBookingSales/index.js +392 -304
- package/dist/solution/UnifiedBookingSales/types.d.ts +7 -0
- package/dist/solution/VenueBooking/index.d.ts +1 -0
- package/dist/solution/VenueBooking/index.js +34 -24
- package/dist/types/index.d.ts +1 -0
- package/dist/utils/payment-number.d.ts +9 -0
- package/dist/utils/payment-number.js +69 -0
- package/lib/core/index.d.ts +2 -0
- package/lib/core/index.js +4 -0
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
- package/lib/model/strategy/adapter/promotion/examples.js +91 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
- package/lib/model/strategy/adapter/promotion/index.js +2 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
- package/lib/model/strategy/adapter/promotion/type.js +2 -0
- package/lib/modules/BaseModule.d.ts +1 -0
- package/lib/modules/BaseModule.js +24 -37
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
- package/lib/modules/OpenData/index.d.ts +2 -0
- package/lib/modules/OpenData/index.js +5 -0
- package/lib/modules/Order/index.d.ts +41 -10
- package/lib/modules/Order/index.js +322 -86
- package/lib/modules/Order/payment-utils.d.ts +26 -0
- package/lib/modules/Order/payment-utils.js +224 -0
- package/lib/modules/Order/types.d.ts +43 -2
- package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
- package/lib/modules/Order/utils.js +11 -4
- package/lib/modules/Payment/index.d.ts +2 -0
- package/lib/modules/Payment/index.js +34 -13
- package/lib/modules/Payment/types.d.ts +107 -28
- package/lib/modules/Payment/types.js +4 -3
- package/lib/modules/Payment/walletpass.d.ts +38 -1
- package/lib/modules/Payment/walletpass.js +730 -21
- package/lib/modules/ProductList/index.js +9 -1
- package/lib/modules/Rules/index.d.ts +3 -0
- package/lib/modules/Rules/index.js +39 -10
- package/lib/server/index.d.ts +16 -0
- package/lib/server/index.js +677 -28
- package/lib/server/modules/index.d.ts +1 -1
- package/lib/server/modules/order/index.d.ts +70 -4
- package/lib/server/modules/order/index.js +818 -69
- package/lib/server/modules/order/types.d.ts +25 -3
- package/lib/server/modules/order/types.js +1 -0
- package/lib/solution/BaseSales/index.d.ts +114 -14
- package/lib/solution/BaseSales/index.js +907 -58
- package/lib/solution/BaseSales/types.d.ts +55 -1
- package/lib/solution/BaseSales/types.js +2 -1
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
- package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +8 -16
- package/lib/solution/BookingTicket/index.js +63 -9
- package/lib/solution/BookingTicket/types.d.ts +1 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
- package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
- package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
- package/lib/solution/Sales/index.d.ts +1 -0
- package/lib/solution/Sales/index.js +5 -3
- package/lib/solution/ScanOrder/index.js +8 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +3 -0
- package/lib/solution/UnifiedBookingSales/index.js +48 -2
- package/lib/solution/UnifiedBookingSales/types.d.ts +7 -0
- package/lib/solution/VenueBooking/index.d.ts +1 -0
- package/lib/solution/VenueBooking/index.js +13 -6
- package/lib/types/index.d.ts +1 -0
- package/lib/utils/payment-number.d.ts +9 -0
- package/lib/utils/payment-number.js +64 -0
- package/package.json +1 -1
|
@@ -150,7 +150,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
// 编辑商品已有商品券
|
|
153
|
-
if (productList.every(function (item) {
|
|
153
|
+
if (productList.length > 0 && productList.every(function (item) {
|
|
154
154
|
var _product$discount_lis;
|
|
155
155
|
var product = _this2.hooks.getProduct(item);
|
|
156
156
|
return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) || product.total == 0);
|
|
@@ -214,6 +214,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
214
214
|
return {
|
|
215
215
|
isAvailable: hasApplicableDiscount,
|
|
216
216
|
discountList: hasApplicableDiscount ? result.discountList : oldDiscountList,
|
|
217
|
+
evaluatedDiscountList: result.discountList,
|
|
217
218
|
productList: hasApplicableDiscount ? result.productList : productList,
|
|
218
219
|
unavailableReason: unavailableReason
|
|
219
220
|
};
|
|
@@ -241,23 +242,37 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
241
242
|
value: function resolveDiscountListForManualOverride(discountList) {
|
|
242
243
|
return this.excludeDiscountListByType(discountList, 'promotion');
|
|
243
244
|
}
|
|
245
|
+
}, {
|
|
246
|
+
key: "isItemRewardProductDiscount",
|
|
247
|
+
value: function isItemRewardProductDiscount(product) {
|
|
248
|
+
var _product$_promotion;
|
|
249
|
+
var discountList = Array.isArray(product === null || product === void 0 ? void 0 : product.discount_list) ? product.discount_list : [];
|
|
250
|
+
return (product === null || product === void 0 || (_product$_promotion = product._promotion) === null || _product$_promotion === void 0 ? void 0 : _product$_promotion.actionType) === 'ITEM_REWARD' && discountList.some(function (item) {
|
|
251
|
+
var _item$metadata, _item$metadata2;
|
|
252
|
+
return (item === null || item === void 0 ? void 0 : item.type) === 'product' && (item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.source) === 'promotion' && (item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.actionType) === 'ITEM_REWARD';
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
244
256
|
// 获取券不可用的原因
|
|
245
257
|
}, {
|
|
246
258
|
key: "getUnavailableReason",
|
|
247
259
|
value: function getUnavailableReason(discountList, productList) {
|
|
260
|
+
var _this3 = this;
|
|
248
261
|
// 检查时间限制
|
|
249
262
|
var _iterator = _createForOfIteratorHelper(discountList),
|
|
250
263
|
_step;
|
|
251
264
|
try {
|
|
252
265
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
253
266
|
var discount = _step.value;
|
|
254
|
-
var
|
|
267
|
+
var bookingTimes = productList.length ? productList.map(function (item) {
|
|
268
|
+
var product = _this3.hooks.getProduct(item);
|
|
269
|
+
return ((product === null || product === void 0 ? void 0 : product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss');
|
|
270
|
+
}) : [dayjs().format('YYYY-MM-DD HH:mm:ss')];
|
|
271
|
+
var _iterator3 = _createForOfIteratorHelper(bookingTimes),
|
|
255
272
|
_step3;
|
|
256
273
|
try {
|
|
257
274
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
258
|
-
var
|
|
259
|
-
var product = this.hooks.getProduct(item);
|
|
260
|
-
var bookingTime = ((product === null || product === void 0 ? void 0 : product.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss');
|
|
275
|
+
var bookingTime = _step3.value;
|
|
261
276
|
var filteredList = filterDiscountListByBookingTime([discount], bookingTime);
|
|
262
277
|
if (filteredList.length === 0) {
|
|
263
278
|
return UnavailableReason.TimeLimit;
|
|
@@ -288,12 +303,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
288
303
|
try {
|
|
289
304
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
290
305
|
var _limitedData$product_;
|
|
291
|
-
var
|
|
292
|
-
var
|
|
306
|
+
var item = _step4.value;
|
|
307
|
+
var product = this.hooks.getProduct(item);
|
|
293
308
|
if (limitedData.type === 'product_all') {
|
|
294
309
|
hasApplicableProduct = true;
|
|
295
310
|
break;
|
|
296
|
-
} else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(
|
|
311
|
+
} else if ((_limitedData$product_ = limitedData.product_ids) !== null && _limitedData$product_ !== void 0 && _limitedData$product_.includes(product.id)) {
|
|
297
312
|
hasApplicableProduct = true;
|
|
298
313
|
break;
|
|
299
314
|
}
|
|
@@ -318,7 +333,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
318
333
|
key: "calcDiscount",
|
|
319
334
|
value: function calcDiscount(_ref2, options) {
|
|
320
335
|
var _options$selectedList,
|
|
321
|
-
|
|
336
|
+
_this4 = this;
|
|
322
337
|
var discountList = _ref2.discountList,
|
|
323
338
|
productList = _ref2.productList,
|
|
324
339
|
holders = _ref2.holders,
|
|
@@ -411,7 +426,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
411
426
|
var flattenProductsWithBundle = function flattenProductsWithBundle(productList) {
|
|
412
427
|
var flattened = [];
|
|
413
428
|
productList.forEach(function (originProduct) {
|
|
414
|
-
var product =
|
|
429
|
+
var product = _this4.hooks.getProduct(originProduct);
|
|
415
430
|
|
|
416
431
|
// 1. 添加主商品
|
|
417
432
|
flattened.push({
|
|
@@ -430,6 +445,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
430
445
|
// 2. 展开 bundle 子商品
|
|
431
446
|
if (product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0) {
|
|
432
447
|
product.bundle.forEach(function (bundleItem, bundleIndex) {
|
|
448
|
+
var _ref3, _bundleItem$bundle_pr;
|
|
433
449
|
flattened.push({
|
|
434
450
|
type: 'bundle',
|
|
435
451
|
originProduct: originProduct,
|
|
@@ -438,8 +454,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
438
454
|
bundleIndex: bundleIndex,
|
|
439
455
|
// 虚拟商品属性
|
|
440
456
|
price: Number(bundleItem.price || 0),
|
|
441
|
-
id: bundleItem._bundle_product_id,
|
|
442
|
-
// 🔥 使用 _bundle_product_id
|
|
457
|
+
id: (_ref3 = (_bundleItem$bundle_pr = bundleItem.bundle_product_id) !== null && _bundleItem$bundle_pr !== void 0 ? _bundleItem$bundle_pr : bundleItem._bundle_product_id) !== null && _ref3 !== void 0 ? _ref3 : bundleItem.product_id,
|
|
443
458
|
_id: "".concat(product._id, "_bundle_").concat(bundleIndex),
|
|
444
459
|
parentId: product._id,
|
|
445
460
|
num: bundleItem.num || 1,
|
|
@@ -588,10 +603,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
588
603
|
|
|
589
604
|
// 对扁平化后的列表按价格降序排序(用于应用优惠券时优先选择高价商品)
|
|
590
605
|
var sortedFlattenedList = flattenedList.sort(function (a, b) {
|
|
591
|
-
var
|
|
606
|
+
var _ref4, _a$original_price, _ref5, _b$original_price;
|
|
592
607
|
// 子商品优先使用 original_price,主商品使用 price
|
|
593
|
-
var priceA = new Decimal(a.type === 'bundle' ? (
|
|
594
|
-
var priceB = new Decimal(b.type === 'bundle' ? (
|
|
608
|
+
var priceA = new Decimal(a.type === 'bundle' ? (_ref4 = (_a$original_price = a.original_price) !== null && _a$original_price !== void 0 ? _a$original_price : a.price) !== null && _ref4 !== void 0 ? _ref4 : '0' : a.price || '0');
|
|
609
|
+
var priceB = new Decimal(b.type === 'bundle' ? (_ref5 = (_b$original_price = b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b.price) !== null && _ref5 !== void 0 ? _ref5 : '0' : b.price || '0');
|
|
595
610
|
if (priceA.equals(priceB)) {
|
|
596
611
|
// 价格相同时,主商品优先
|
|
597
612
|
if (a.type !== b.type) {
|
|
@@ -713,7 +728,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
713
728
|
|
|
714
729
|
// 辅助函数:检查商品是否对某个折扣卡可用
|
|
715
730
|
var checkItemApplicableForDiscount = function checkItemApplicableForDiscount(flatItem, discount) {
|
|
716
|
-
var _product2, _product3,
|
|
731
|
+
var _product, _product2, _product3, _flatItem$bundleItem, _flatItem$bundleItem2, _product4;
|
|
717
732
|
var product;
|
|
718
733
|
if (flatItem.type === 'main') {
|
|
719
734
|
product = flatItem.product;
|
|
@@ -730,9 +745,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
730
745
|
startDate: (_flatItem$parentProdu = flatItem.parentProduct) === null || _flatItem$parentProdu === void 0 ? void 0 : _flatItem$parentProdu.startDate
|
|
731
746
|
};
|
|
732
747
|
}
|
|
748
|
+
if (_this4.isItemRewardProductDiscount(product)) {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
733
751
|
|
|
734
752
|
// 编辑的商品使用了优惠券不可用
|
|
735
|
-
var isAvailableProduct = flatItem.type === 'main' ? !((
|
|
753
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product = product) !== null && _product !== void 0 && _product.booking_id && (_product2 = product) !== null && _product2 !== void 0 && (_product2 = _product2.discount_list) !== null && _product2 !== void 0 && _product2.length && (_product3 = product) !== null && _product3 !== void 0 && (_product3 = _product3.discount_list) !== null && _product3 !== void 0 && _product3.every(function (d) {
|
|
736
754
|
return d.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(d.tag || d.type);
|
|
737
755
|
})) : !(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) {
|
|
738
756
|
return d.id;
|
|
@@ -753,7 +771,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
753
771
|
var limitedData = discount.limited_relation_product_data;
|
|
754
772
|
|
|
755
773
|
// 时间限制检查
|
|
756
|
-
var timeLimit = !!filterDiscountListByBookingTime([discount], (((
|
|
774
|
+
var timeLimit = !!filterDiscountListByBookingTime([discount], (((_product4 = product) === null || _product4 === void 0 ? void 0 : _product4.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
757
775
|
if (!timeLimit) {
|
|
758
776
|
return false;
|
|
759
777
|
}
|
|
@@ -773,7 +791,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
773
791
|
}
|
|
774
792
|
|
|
775
793
|
// 套餐规则检查
|
|
776
|
-
var isBundleAvailable =
|
|
794
|
+
var isBundleAvailable = _this4.checkPackageSubItemUsageRules(discount, flatItem);
|
|
777
795
|
return isLimitedProduct && isBundleAvailable;
|
|
778
796
|
};
|
|
779
797
|
|
|
@@ -833,7 +851,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
833
851
|
// 收集该折扣卡适用的商品(排除被其他专属折扣卡占用的商品)
|
|
834
852
|
var applicableProducts = [];
|
|
835
853
|
sortedFlattenedList.forEach(function (flatItem) {
|
|
836
|
-
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price,
|
|
854
|
+
var _flatItem$parentProdu2, _flatItem$parentProdu3, _product$price, _ref6, _flatItem$original_pr;
|
|
837
855
|
// 🔥 检查该商品是否被其他专属折扣卡占用
|
|
838
856
|
var occupyingDiscountId = occupiedItems.get(flatItem._id);
|
|
839
857
|
if (occupyingDiscountId !== undefined && occupyingDiscountId !== discount.id) {
|
|
@@ -861,7 +879,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
861
879
|
|
|
862
880
|
// 对于主商品:使用 price
|
|
863
881
|
// 对于子商品:优先使用 flatItem.original_price,否则使用 flatItem.price
|
|
864
|
-
var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((
|
|
882
|
+
var originalAmount = flatItem.type === 'main' ? Number((_product$price = product.price) !== null && _product$price !== void 0 ? _product$price : 0) : Number((_ref6 = (_flatItem$original_pr = flatItem.original_price) !== null && _flatItem$original_pr !== void 0 ? _flatItem$original_pr : flatItem.price) !== null && _ref6 !== void 0 ? _ref6 : 0);
|
|
865
883
|
|
|
866
884
|
// 传递 parentQuantity 用于差值处理时判断是否是真正的"数量为1"
|
|
867
885
|
var productData = {
|
|
@@ -916,32 +934,33 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
916
934
|
};
|
|
917
935
|
originProduct = flatItem.originProduct;
|
|
918
936
|
}
|
|
937
|
+
var isItemRewardProductDiscount = _this4.isItemRewardProductDiscount(product);
|
|
919
938
|
addModeDiscount.forEach(function (discount) {
|
|
920
|
-
var _product6, _product7, _product8,
|
|
939
|
+
var _product5, _product6, _product7, _product8, _flatItem$bundleItem3, _flatItem$bundleItem4, _discount$config;
|
|
921
940
|
var limitedData = discount === null || discount === void 0 ? void 0 : discount.limited_relation_product_data;
|
|
922
941
|
// 拿到discount配置的holder信息 product信息 product.holder 加在 isLimitedProduct
|
|
923
942
|
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;
|
|
924
|
-
var isHolderMatch =
|
|
943
|
+
var isHolderMatch = _this4.checkHolderMatch(discount, {
|
|
925
944
|
isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
926
945
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
927
946
|
}, holders);
|
|
928
947
|
var timeLimit = true;
|
|
929
|
-
timeLimit = !!filterDiscountListByBookingTime([discount], (((
|
|
948
|
+
timeLimit = !!filterDiscountListByBookingTime([discount], (((_product5 = product) === null || _product5 === void 0 ? void 0 : _product5.startDate) || dayjs()).format('YYYY-MM-DD HH:mm:ss')).length;
|
|
930
949
|
// 是符合折扣的商品
|
|
931
950
|
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;
|
|
932
951
|
|
|
933
952
|
// 编辑的商品 使用了优惠券不可用
|
|
934
|
-
var isAvailableProduct = flatItem.type === 'main' ? !((
|
|
953
|
+
var isAvailableProduct = flatItem.type === 'main' ? !((_product6 = product) !== null && _product6 !== void 0 && _product6.booking_id && (_product7 = product) !== null && _product7 !== void 0 && (_product7 = _product7.discount_list) !== null && _product7 !== void 0 && _product7.length && (_product8 = product) !== null && _product8 !== void 0 && (_product8 = _product8.discount_list) !== null && _product8 !== void 0 && _product8.every(function (discount) {
|
|
935
954
|
return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
|
|
936
955
|
})) : !(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) {
|
|
937
956
|
return discount.id;
|
|
938
957
|
}));
|
|
939
958
|
|
|
940
959
|
// 套餐是否可用判断
|
|
941
|
-
var isBundleAvailable =
|
|
960
|
+
var isBundleAvailable = _this4.checkPackageSubItemUsageRules(discount, flatItem);
|
|
942
961
|
|
|
943
962
|
// 判断优惠券是否适用于该商品
|
|
944
|
-
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
|
|
963
|
+
if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
|
|
945
964
|
var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
|
|
946
965
|
// 记录此优惠券适用的商品
|
|
947
966
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
@@ -990,13 +1009,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
990
1009
|
};
|
|
991
1010
|
var optionDiscountAmount = 0;
|
|
992
1011
|
var discountedOptions = options.map(function (option) {
|
|
993
|
-
var
|
|
1012
|
+
var _ref7, _ref8, _option$_original_pri, _ref9, _option$num, _rest$price, _option$_original_pri2;
|
|
994
1013
|
// 折前单价:优先 price,缺失再 add_price;已写回折后价时用 _original_price(或旧字段 _original_add_price)
|
|
995
|
-
var rawUnit = (
|
|
1014
|
+
var rawUnit = (_ref7 = (_ref8 = (_option$_original_pri = option._original_price) !== null && _option$_original_pri !== void 0 ? _option$_original_pri : option._original_add_price) !== null && _ref8 !== void 0 ? _ref8 : option.price) !== null && _ref7 !== void 0 ? _ref7 : option.add_price;
|
|
996
1015
|
var baseUnitNum = Number(rawUnit !== null && rawUnit !== void 0 ? rawUnit : 0);
|
|
997
1016
|
if (baseUnitNum <= 0) return option;
|
|
998
1017
|
var discountedPrice = getDiscountAmount(discount, baseUnitNum, baseUnitNum);
|
|
999
|
-
var optQty = Number((
|
|
1018
|
+
var optQty = Number((_ref9 = (_option$num = option.num) !== null && _option$num !== void 0 ? _option$num : option.quantity) !== null && _ref9 !== void 0 ? _ref9 : 1);
|
|
1000
1019
|
optionDiscountAmount = new Decimal(optionDiscountAmount).plus(new Decimal(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
|
|
1001
1020
|
var _original_add_price = option._original_add_price,
|
|
1002
1021
|
rest = _objectWithoutProperties(option, _excluded);
|
|
@@ -1030,9 +1049,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1030
1049
|
var getOptionTotal = function getOptionTotal(options) {
|
|
1031
1050
|
if (!(options !== null && options !== void 0 && options.length)) return 0;
|
|
1032
1051
|
return options.reduce(function (sum, opt) {
|
|
1033
|
-
var
|
|
1034
|
-
var unit = Number((
|
|
1035
|
-
var n = Number((
|
|
1052
|
+
var _ref10, _opt$price, _ref11, _opt$num;
|
|
1053
|
+
var unit = Number((_ref10 = (_opt$price = opt.price) !== null && _opt$price !== void 0 ? _opt$price : opt.add_price) !== null && _ref10 !== void 0 ? _ref10 : 0);
|
|
1054
|
+
var n = Number((_ref11 = (_opt$num = opt.num) !== null && _opt$num !== void 0 ? _opt$num : opt.quantity) !== null && _ref11 !== void 0 ? _ref11 : 1);
|
|
1036
1055
|
return new Decimal(sum).plus(new Decimal(unit).mul(n)).toNumber();
|
|
1037
1056
|
}, 0);
|
|
1038
1057
|
};
|
|
@@ -1040,7 +1059,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1040
1059
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
1041
1060
|
// 🔥 使用扁平化后的列表进行处理
|
|
1042
1061
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
1043
|
-
var
|
|
1062
|
+
var _product9, _originProduct, _originProduct2, _originProduct3, _product$discount_lis2, _product10;
|
|
1044
1063
|
// 获取商品数据
|
|
1045
1064
|
var product, originProduct;
|
|
1046
1065
|
if (flatItem.type === 'main') {
|
|
@@ -1064,8 +1083,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1064
1083
|
};
|
|
1065
1084
|
originProduct = flatItem.originProduct;
|
|
1066
1085
|
}
|
|
1067
|
-
var isPersistedProduct = ((
|
|
1068
|
-
var hasExistingWalletDiscount = ((_product$discount_lis2 = product.discount_list) === null || _product$discount_lis2 === void 0 ? void 0 : _product$discount_lis2.length) && ((
|
|
1086
|
+
var isPersistedProduct = ((_product9 = product) === null || _product9 === void 0 ? void 0 : _product9.booking_id) || ((_originProduct = originProduct) === null || _originProduct === void 0 ? void 0 : _originProduct.order_detail_id) || ((_originProduct2 = originProduct) === null || _originProduct2 === void 0 ? void 0 : _originProduct2.orderDetailId) || ((_originProduct3 = originProduct) === null || _originProduct3 === void 0 ? void 0 : _originProduct3.booking_id);
|
|
1087
|
+
var hasExistingWalletDiscount = ((_product$discount_lis2 = product.discount_list) === null || _product$discount_lis2 === void 0 ? void 0 : _product$discount_lis2.length) && ((_product10 = product) === null || _product10 === void 0 || (_product10 = _product10.discount_list) === null || _product10 === void 0 ? void 0 : _product10.every(function (discount) {
|
|
1069
1088
|
var _discount$id, _discount$discount4;
|
|
1070
1089
|
var discountIdentity = (_discount$id = discount.id) !== null && _discount$id !== void 0 ? _discount$id : (_discount$discount4 = discount.discount) === null || _discount$discount4 === void 0 ? void 0 : _discount$discount4.resource_id;
|
|
1071
1090
|
var discountType = discount.tag || discount.type;
|
|
@@ -1087,6 +1106,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1087
1106
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
1088
1107
|
var applicableDiscounts = sortedDiscountList.filter(function (discount) {
|
|
1089
1108
|
var _product$discount_lis3, _product$discount_lis4;
|
|
1109
|
+
if (_this4.isItemRewardProductDiscount(product)) return false;
|
|
1090
1110
|
// 🔥 检查策略可用性(针对 good_pass 和折扣卡)
|
|
1091
1111
|
var discountType = discount.tag || discount.type;
|
|
1092
1112
|
var currentOriginUid = getOriginProductUid(originProduct);
|
|
@@ -1132,7 +1152,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1132
1152
|
|
|
1133
1153
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
1134
1154
|
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;
|
|
1135
|
-
var isHolderMatch =
|
|
1155
|
+
var isHolderMatch = _this4.checkHolderMatch(discount, {
|
|
1136
1156
|
isNeedHolder: resolveIsFormSubject(_tempVar) && !(_tempVar !== null && _tempVar !== void 0 && _tempVar.isNormalProduct),
|
|
1137
1157
|
holder_id: (_tempVar === null || _tempVar === void 0 ? void 0 : _tempVar.holder_id) || product.holder_id
|
|
1138
1158
|
}, holders);
|
|
@@ -1150,13 +1170,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1150
1170
|
return false;
|
|
1151
1171
|
}
|
|
1152
1172
|
// 检查 package_sub_item_usage_rules
|
|
1153
|
-
if (!
|
|
1173
|
+
if (!_this4.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1154
1174
|
return false;
|
|
1155
1175
|
}
|
|
1156
1176
|
return true;
|
|
1157
1177
|
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
1158
1178
|
// 检查 package_sub_item_usage_rules
|
|
1159
|
-
if (!
|
|
1179
|
+
if (!_this4.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1160
1180
|
return false;
|
|
1161
1181
|
}
|
|
1162
1182
|
return true;
|
|
@@ -1164,28 +1184,36 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1164
1184
|
return false;
|
|
1165
1185
|
});
|
|
1166
1186
|
|
|
1167
|
-
//
|
|
1168
|
-
//
|
|
1169
|
-
|
|
1170
|
-
|
|
1187
|
+
// 用户显式点击某张折扣卡时,本次选择优先于自动排序和扫码默认选择。
|
|
1188
|
+
// 目标仍必须在当前商品的 applicableDiscounts 中,因此不会绕过 Holder、时间或商品范围校验。
|
|
1189
|
+
var explicitlySelectedDiscountCard = (options === null || options === void 0 ? void 0 : options.isSelected) === true && options.discountId !== undefined ? applicableDiscounts.find(function (discount) {
|
|
1190
|
+
var discountType = discount.tag || discount.type;
|
|
1191
|
+
return String(discount.id) === String(options.discountId) && ['discount_card', 'product_discount_card'].includes(discountType);
|
|
1192
|
+
}) : undefined;
|
|
1193
|
+
|
|
1194
|
+
// 没有显式选择时保持现有行为:扫码且已选中的折扣卡优先,否则使用自动排序第一项。
|
|
1195
|
+
var scannedSelectedDiscountCard = applicableDiscounts.find(function (n) {
|
|
1171
1196
|
return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
|
|
1172
1197
|
});
|
|
1198
|
+
var selectedDiscountCard = explicitlySelectedDiscountCard || scannedSelectedDiscountCard;
|
|
1173
1199
|
var selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
|
|
1174
1200
|
|
|
1175
1201
|
// 如果是手动折扣,则不适用优惠券
|
|
1176
1202
|
var isManualDiscount = false;
|
|
1203
|
+
var isItemRewardProductDiscount = false;
|
|
1177
1204
|
if (flatItem.type === 'main') {
|
|
1178
|
-
var _product$discount_lis5, _product$discount_lis6,
|
|
1205
|
+
var _product$discount_lis5, _product$discount_lis6, _product11, _product11$every;
|
|
1179
1206
|
// 主商品:判断自身是否手动折扣
|
|
1180
1207
|
isManualDiscount = typeof product.isManualDiscount === 'boolean' ? product.isManualDiscount : ((_product$discount_lis5 = product.discount_list) === null || _product$discount_lis5 === void 0 ? void 0 : _product$discount_lis5.some(function (item) {
|
|
1181
1208
|
return item.type === 'product';
|
|
1182
1209
|
})) || product.total != product.origin_total && (product.bundle || []).every(function (item) {
|
|
1183
|
-
var
|
|
1184
|
-
return !((
|
|
1185
|
-
}) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((
|
|
1210
|
+
var _ref12;
|
|
1211
|
+
return !((_ref12 = item.discount_list || []) !== null && _ref12 !== void 0 && _ref12.length);
|
|
1212
|
+
}) && (!((_product$discount_lis6 = product.discount_list) !== null && _product$discount_lis6 !== void 0 && _product$discount_lis6.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
|
|
1186
1213
|
return item.type === 'product';
|
|
1187
1214
|
})));
|
|
1188
|
-
|
|
1215
|
+
isItemRewardProductDiscount = _this4.isItemRewardProductDiscount(product);
|
|
1216
|
+
if (product.inPromotion && !isItemRewardProductDiscount) {
|
|
1189
1217
|
isManualDiscount = false;
|
|
1190
1218
|
}
|
|
1191
1219
|
} else {
|
|
@@ -1196,8 +1224,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1196
1224
|
isManualDiscount = typeof parentProduct.isManualDiscount === 'boolean' ? parentProduct.isManualDiscount : ((_parentProduct$discou = parentProduct.discount_list) === null || _parentProduct$discou === void 0 ? void 0 : _parentProduct$discou.some(function (item) {
|
|
1197
1225
|
return item.type === 'product';
|
|
1198
1226
|
})) || parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(function (item) {
|
|
1199
|
-
var
|
|
1200
|
-
return !((
|
|
1227
|
+
var _ref13;
|
|
1228
|
+
return !((_ref13 = item.discount_list || []) !== null && _ref13 !== void 0 && _ref13.length);
|
|
1201
1229
|
}) && (!((_parentProduct$discou2 = parentProduct.discount_list) !== null && _parentProduct$discou2 !== void 0 && _parentProduct$discou2.length) || (parentProduct === null || parentProduct === void 0 || (_parentProduct$discou3 = parentProduct.discount_list) === null || _parentProduct$discou3 === void 0 || (_parentProduct$discou4 = _parentProduct$discou3.every) === null || _parentProduct$discou4 === void 0 ? void 0 : _parentProduct$discou4.call(_parentProduct$discou3, function (item) {
|
|
1202
1230
|
return item.type === 'product';
|
|
1203
1231
|
})));
|
|
@@ -1267,7 +1295,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1267
1295
|
// 主商品:保持原有逻辑,还原 option 价格
|
|
1268
1296
|
var restoredOptions = restoreOptionPrices(product.options);
|
|
1269
1297
|
if (product.isClient) {
|
|
1270
|
-
processedProductsMap.set(product._id, [
|
|
1298
|
+
processedProductsMap.set(product._id, [_this4.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {} : {
|
|
1271
1299
|
origin_total: getProductOriginTotalPrice({
|
|
1272
1300
|
product: {
|
|
1273
1301
|
original_price: product.original_price
|
|
@@ -1287,36 +1315,39 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1287
1315
|
price: product.price,
|
|
1288
1316
|
options: restoredOptions
|
|
1289
1317
|
}), {}, {
|
|
1290
|
-
discount_list: isManualDiscount ?
|
|
1318
|
+
discount_list: isManualDiscount ? _this4.resolveDiscountListForManualOverride(product.discount_list) : _this4.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1291
1319
|
}))]);
|
|
1292
1320
|
} else {
|
|
1293
|
-
var
|
|
1294
|
-
var total = product.inPromotion ? (
|
|
1321
|
+
var _ref14, _product$_promotion$f, _product12, _product$origin_total;
|
|
1322
|
+
var total = product.inPromotion ? (_ref14 = (_product$_promotion$f = (_product12 = product) === null || _product12 === void 0 || (_product12 = _product12._promotion) === null || _product12 === void 0 ? void 0 : _product12.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref14 !== void 0 ? _ref14 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1295
1323
|
var main_product_selling_price = product.price;
|
|
1296
1324
|
if ((product.discount_list || []).some(function (item) {
|
|
1297
1325
|
return item.type === 'promotion';
|
|
1298
|
-
}) || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
1326
|
+
}) || isItemRewardProductDiscount || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
1299
1327
|
var _product$total, _product$main_product;
|
|
1300
1328
|
total = (_product$total = product.total) !== null && _product$total !== void 0 ? _product$total : product.origin_total;
|
|
1301
1329
|
main_product_selling_price = (_product$main_product = product.main_product_selling_price) !== null && _product$main_product !== void 0 ? _product$main_product : main_product_selling_price;
|
|
1302
1330
|
}
|
|
1303
|
-
processedProductsMap.set(product._id, [
|
|
1304
|
-
price: product.price
|
|
1305
|
-
|
|
1331
|
+
processedProductsMap.set(product._id, [_this4.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? _objectSpread({
|
|
1332
|
+
price: product.price,
|
|
1333
|
+
main_product_selling_price: isItemRewardProductDiscount ? main_product_selling_price : product.price
|
|
1334
|
+
}, isItemRewardProductDiscount ? {
|
|
1335
|
+
total: total
|
|
1336
|
+
} : {}) : {
|
|
1306
1337
|
_id: product._id.split('___')[0] + '___' + index,
|
|
1307
1338
|
total: total,
|
|
1308
1339
|
price: product.price,
|
|
1309
1340
|
main_product_selling_price: main_product_selling_price,
|
|
1310
1341
|
options: restoredOptions
|
|
1311
1342
|
}), {}, {
|
|
1312
|
-
discount_list: isManualDiscount ?
|
|
1343
|
+
discount_list: isManualDiscount ? _this4.resolveDiscountListForManualOverride(product.discount_list) : _this4.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1313
1344
|
}))]);
|
|
1314
1345
|
}
|
|
1315
1346
|
} else {
|
|
1316
1347
|
var _flatItem$bundleItem8, _flatItem$bundleItem9;
|
|
1317
1348
|
// bundle子商品:保存到扁平化Map
|
|
1318
1349
|
processedFlatItemsMap.set(flatItem._id, [_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1319
|
-
discount_list: isManualDiscount ?
|
|
1350
|
+
discount_list: isManualDiscount ? _this4.resolveDiscountListForManualOverride(((_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.discount_list) || []) : _this4.filterDiscountListByType(((_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.discount_list) || [], 'promotion'),
|
|
1320
1351
|
price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
|
|
1321
1352
|
processed: true
|
|
1322
1353
|
})]);
|
|
@@ -1357,8 +1388,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1357
1388
|
var _product$total2;
|
|
1358
1389
|
_total = (_product$total2 = product.total) !== null && _product$total2 !== void 0 ? _product$total2 : product.origin_total;
|
|
1359
1390
|
}
|
|
1360
|
-
arr.push(
|
|
1361
|
-
discount_list:
|
|
1391
|
+
arr.push(_this4.hooks.setProduct(originProduct, {
|
|
1392
|
+
discount_list: _this4.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1362
1393
|
quantity: totalQuantity - splitCount,
|
|
1363
1394
|
_id: product._id.split('___')[0],
|
|
1364
1395
|
total: _total
|
|
@@ -1382,7 +1413,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1382
1413
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
1383
1414
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
1384
1415
|
// 如果当前 product 有 discount_list,则先从 origin_total 拿
|
|
1385
|
-
if (
|
|
1416
|
+
if (_this4.filterDiscountListByType(product.discount_list, 'promotion').length && product.origin_total) {
|
|
1386
1417
|
productOriginTotal = product.origin_total;
|
|
1387
1418
|
}
|
|
1388
1419
|
// 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
|
|
@@ -1470,7 +1501,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1470
1501
|
// 记录应用了优惠券的商品
|
|
1471
1502
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
1472
1503
|
if (product.isClient) {
|
|
1473
|
-
arr.push(
|
|
1504
|
+
arr.push(_this4.hooks.setProduct(originProduct, {
|
|
1474
1505
|
discount_list: [discountDetail],
|
|
1475
1506
|
// good_pass:主商品价以折后价为准;勿用 product.price - amount(amount 含 option 优惠时会算错)
|
|
1476
1507
|
price: isGoodPass ? mainProductSellingPrice : product.price,
|
|
@@ -1488,8 +1519,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1488
1519
|
options: discountedOptions
|
|
1489
1520
|
}));
|
|
1490
1521
|
} else {
|
|
1491
|
-
arr.push(
|
|
1492
|
-
discount_list:
|
|
1522
|
+
arr.push(_this4.hooks.setProduct(originProduct, {
|
|
1523
|
+
discount_list: _this4.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1493
1524
|
_id: product._id.split('___')[0] + '___' + _selectedDiscount.id + index,
|
|
1494
1525
|
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1495
1526
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
@@ -1574,7 +1605,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1574
1605
|
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1575
1606
|
num: normalNum,
|
|
1576
1607
|
quantity: normalNum,
|
|
1577
|
-
discount_list:
|
|
1608
|
+
discount_list: _this4.filterDiscountListByType(flatItem.discount_list, 'promotion'),
|
|
1578
1609
|
processed: true
|
|
1579
1610
|
}));
|
|
1580
1611
|
}
|
|
@@ -1644,7 +1675,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1644
1675
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1645
1676
|
total: targetProductTotal,
|
|
1646
1677
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
1647
|
-
discount_list:
|
|
1678
|
+
discount_list: _this4.filterDiscountListByType(flatItem.discount_list, 'promotion').concat([_discountDetail2]),
|
|
1648
1679
|
processed: true
|
|
1649
1680
|
}));
|
|
1650
1681
|
}
|
|
@@ -1656,7 +1687,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1656
1687
|
var reconstructProductsWithBundle = function reconstructProductsWithBundle(processedProductsMap, processedFlatItemsMap, originalProductList) {
|
|
1657
1688
|
var result = [];
|
|
1658
1689
|
originalProductList.forEach(function (originProduct) {
|
|
1659
|
-
var product =
|
|
1690
|
+
var product = _this4.hooks.getProduct(originProduct);
|
|
1660
1691
|
|
|
1661
1692
|
// 获取主商品处理结果
|
|
1662
1693
|
var mainProductArr = processedProductsMap.get(product._id);
|
|
@@ -1665,8 +1696,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1665
1696
|
var getDefaultProduct = function getDefaultProduct() {
|
|
1666
1697
|
var restoredOptions = restoreOptionPrices(product.options);
|
|
1667
1698
|
if (product.isClient) {
|
|
1668
|
-
return
|
|
1669
|
-
discount_list:
|
|
1699
|
+
return _this4.hooks.setProduct(originProduct, {
|
|
1700
|
+
discount_list: _this4.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1670
1701
|
price: product.price,
|
|
1671
1702
|
origin_total: getProductOriginTotalPrice({
|
|
1672
1703
|
product: {
|
|
@@ -1687,8 +1718,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1687
1718
|
options: restoredOptions
|
|
1688
1719
|
});
|
|
1689
1720
|
} else {
|
|
1690
|
-
return
|
|
1691
|
-
discount_list:
|
|
1721
|
+
return _this4.hooks.setProduct(originProduct, {
|
|
1722
|
+
discount_list: _this4.filterDiscountListByType(product.discount_list, 'promotion'),
|
|
1692
1723
|
total: product.total,
|
|
1693
1724
|
origin_total: product.origin_total,
|
|
1694
1725
|
price: product.price,
|
|
@@ -1736,10 +1767,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1736
1767
|
}
|
|
1737
1768
|
|
|
1738
1769
|
// 🔥 2. 如果有子商品应用了商品券,且主商品数量大于1,需要拆分主商品
|
|
1739
|
-
var mainProductQuantity = mainProductArr[0] ?
|
|
1770
|
+
var mainProductQuantity = mainProductArr[0] ? _this4.hooks.getProduct(mainProductArr[0]).quantity : 1;
|
|
1740
1771
|
if (hasGoodPassApplied && mainProductArr.length === 1 && mainProductQuantity > 1) {
|
|
1741
1772
|
var mainProduct = mainProductArr[0];
|
|
1742
|
-
var mainProductData =
|
|
1773
|
+
var mainProductData = _this4.hooks.getProduct(mainProduct);
|
|
1743
1774
|
|
|
1744
1775
|
// 🔥 方案:拆分成2个主商品
|
|
1745
1776
|
// 1. 一个主商品(qty=1)包含拆分后的bundle
|
|
@@ -1754,11 +1785,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1754
1785
|
processedItems.forEach(function (item) {
|
|
1755
1786
|
// 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
|
|
1756
1787
|
var updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
1757
|
-
var _item$
|
|
1788
|
+
var _item$metadata3;
|
|
1758
1789
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1759
1790
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1760
1791
|
num: item.num,
|
|
1761
|
-
custom_product_bundle_map_id: (_item$
|
|
1792
|
+
custom_product_bundle_map_id: (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.custom_product_bundle_map_id
|
|
1762
1793
|
})
|
|
1763
1794
|
// num: item.num, // 使用拆分后的 num
|
|
1764
1795
|
});
|
|
@@ -1777,11 +1808,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1777
1808
|
if (item.processed) {
|
|
1778
1809
|
// 🔥 同样需要更新 discount_list 中的 num
|
|
1779
1810
|
var _updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
1780
|
-
var _item$
|
|
1811
|
+
var _item$metadata4;
|
|
1781
1812
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
1782
1813
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
1783
1814
|
num: item.num,
|
|
1784
|
-
custom_product_bundle_map_id: (_item$
|
|
1815
|
+
custom_product_bundle_map_id: (_item$metadata4 = item.metadata) === null || _item$metadata4 === void 0 ? void 0 : _item$metadata4.custom_product_bundle_map_id
|
|
1785
1816
|
})
|
|
1786
1817
|
// num: item.num, // 使用当前的 num
|
|
1787
1818
|
});
|
|
@@ -1822,8 +1853,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1822
1853
|
|
|
1823
1854
|
// 🔥 使用更新后的列表计算折扣金额
|
|
1824
1855
|
var mainDiscountList = updatedMainDiscountList.filter(function (item) {
|
|
1825
|
-
var _item$
|
|
1826
|
-
return !(item !== null && item !== void 0 && (_item$
|
|
1856
|
+
var _item$metadata5;
|
|
1857
|
+
return !(item !== null && item !== void 0 && (_item$metadata5 = item.metadata) !== null && _item$metadata5 !== void 0 && _item$metadata5.custom_product_bundle_map_id);
|
|
1827
1858
|
});
|
|
1828
1859
|
if (mainDiscountList && mainDiscountList.length > 0) {
|
|
1829
1860
|
var _Decimal$minus$toNumb, _mainProductData$orig;
|
|
@@ -1854,7 +1885,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1854
1885
|
}
|
|
1855
1886
|
|
|
1856
1887
|
// 添加第一个主商品:qty=1,包含拆分后的bundle
|
|
1857
|
-
result.push(
|
|
1888
|
+
result.push(_this4.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
1858
1889
|
_id: "".concat(mainProductData._id.split('___')[0], "___split_discount"),
|
|
1859
1890
|
quantity: 1,
|
|
1860
1891
|
discount_list: updatedMainDiscountList,
|
|
@@ -1896,8 +1927,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1896
1927
|
|
|
1897
1928
|
// 🔥 使用更新后的列表计算折扣金额
|
|
1898
1929
|
var mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(function (item) {
|
|
1899
|
-
var _item$
|
|
1900
|
-
return !(item !== null && item !== void 0 && (_item$
|
|
1930
|
+
var _item$metadata6;
|
|
1931
|
+
return !(item !== null && item !== void 0 && (_item$metadata6 = item.metadata) !== null && _item$metadata6 !== void 0 && _item$metadata6.custom_product_bundle_map_id);
|
|
1901
1932
|
});
|
|
1902
1933
|
if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
|
|
1903
1934
|
var _Decimal$minus$toNumb2, _mainProductData$orig2;
|
|
@@ -1926,7 +1957,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1926
1957
|
newOriginTotalOriginal = new Decimal(newOriginTotalOriginal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
1927
1958
|
|
|
1928
1959
|
// 添加第二个主商品:qty=原quantity-1,包含原始bundle
|
|
1929
|
-
result.push(
|
|
1960
|
+
result.push(_this4.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
1930
1961
|
_id: "".concat(mainProductData._id.split('___')[0], "___split_normal"),
|
|
1931
1962
|
quantity: mainProductQuantity - 1,
|
|
1932
1963
|
discount_list: updatedMainDiscountListOriginal,
|
|
@@ -1938,8 +1969,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1938
1969
|
} else {
|
|
1939
1970
|
// 🔥 没有子商品被拆分,使用原有逻辑
|
|
1940
1971
|
mainProductArr.forEach(function (mainProduct) {
|
|
1941
|
-
var
|
|
1942
|
-
var mainProductData =
|
|
1972
|
+
var _ref16, _mainProductData$main, _mainProductData$disc, _mainProductData$disc2, _mainProductData$disc3;
|
|
1973
|
+
var mainProductData = _this4.hooks.getProduct(mainProduct);
|
|
1943
1974
|
|
|
1944
1975
|
// 重组bundle
|
|
1945
1976
|
var newBundle = [];
|
|
@@ -1953,9 +1984,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1953
1984
|
} else {
|
|
1954
1985
|
// 🔥 关键:拆分后的bundle item
|
|
1955
1986
|
processedBundleItems.forEach(function (item) {
|
|
1956
|
-
var _item$price,
|
|
1987
|
+
var _item$price, _ref15, _item$bundle_selling_;
|
|
1957
1988
|
var nextBundlePrice = (_item$price = item.price) !== null && _item$price !== void 0 ? _item$price : bundleItem.price;
|
|
1958
|
-
var nextBundleSellingPrice = (
|
|
1989
|
+
var nextBundleSellingPrice = (_ref15 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref15 !== void 0 ? _ref15 : bundleItem.bundle_selling_price;
|
|
1959
1990
|
// 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
|
|
1960
1991
|
var updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
1961
1992
|
var _discount$metadata10;
|
|
@@ -1982,7 +2013,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1982
2013
|
|
|
1983
2014
|
// 主商品已经在前面的 setProduct 中应用过折扣;这里只替换 bundle,
|
|
1984
2015
|
// 避免把主商品 discount_list 再扣一次。
|
|
1985
|
-
var mainSellingPrice = (
|
|
2016
|
+
var mainSellingPrice = (_ref16 = (_mainProductData$main = mainProductData.main_product_selling_price) !== null && _mainProductData$main !== void 0 ? _mainProductData$main : mainProductData.price) !== null && _ref16 !== void 0 ? _ref16 : 0;
|
|
1986
2017
|
var newTotal = Number(mainSellingPrice || 0);
|
|
1987
2018
|
var newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
|
|
1988
2019
|
|
|
@@ -2026,7 +2057,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2026
2057
|
newOriginTotal = new Decimal(newOriginTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
|
|
2027
2058
|
|
|
2028
2059
|
// 生成最终的主商品
|
|
2029
|
-
result.push(
|
|
2060
|
+
result.push(_this4.hooks.setProduct(mainProduct, _objectSpread(_objectSpread({}, mainProductData), {}, {
|
|
2030
2061
|
bundle: newBundle,
|
|
2031
2062
|
total: newTotal,
|
|
2032
2063
|
origin_total: newOriginTotal
|
|
@@ -2131,14 +2162,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2131
2162
|
var ruleType = usageRules.type;
|
|
2132
2163
|
// 套餐适用范围配置
|
|
2133
2164
|
var packageScope = usageRules === null || usageRules === void 0 ? void 0 : usageRules.package_scope;
|
|
2134
|
-
var
|
|
2135
|
-
scopeType =
|
|
2136
|
-
|
|
2137
|
-
exclude_bundle_product_ids =
|
|
2138
|
-
|
|
2139
|
-
include_bundle_product_ids =
|
|
2140
|
-
|
|
2141
|
-
filter =
|
|
2165
|
+
var _ref17 = packageScope || {},
|
|
2166
|
+
scopeType = _ref17.type,
|
|
2167
|
+
_ref17$exclude_bundle = _ref17.exclude_bundle_product_ids,
|
|
2168
|
+
exclude_bundle_product_ids = _ref17$exclude_bundle === void 0 ? [] : _ref17$exclude_bundle,
|
|
2169
|
+
_ref17$include_bundle = _ref17.include_bundle_product_ids,
|
|
2170
|
+
include_bundle_product_ids = _ref17$include_bundle === void 0 ? [] : _ref17$include_bundle,
|
|
2171
|
+
_ref17$filter = _ref17.filter,
|
|
2172
|
+
filter = _ref17$filter === void 0 ? 0 : _ref17$filter;
|
|
2142
2173
|
var isMainProduct = flatItem.type === 'main'; // 单独购买
|
|
2143
2174
|
var isBundleItem = flatItem.type === 'bundle'; // 套餐中购买
|
|
2144
2175
|
var bundleMainProductId = (_flatItem$product = flatItem.product) === null || _flatItem$product === void 0 ? void 0 : _flatItem$product.product_id;
|