@pisell/pisellos 0.0.569 → 0.10.2
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.js +10 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -3
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
- package/dist/model/strategy/adapter/walletPass/example.js +26 -3
- package/dist/model/strategy/adapter/walletPass/index.js +5 -5
- package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
- package/dist/model/strategy/adapter/walletPass/utils.js +17 -92
- package/dist/model/strategy/strategy-example.js +19 -5
- package/dist/modules/BaseModule.d.ts +1 -1
- package/dist/modules/BaseModule.js +8 -10
- package/dist/modules/Cart/index.js +3 -0
- package/dist/modules/Cart/utils/cartProduct.js +1 -0
- package/dist/modules/Cart/utils/cartResource.js +0 -2
- package/dist/modules/Cart/utils/changePrice.js +9 -16
- package/dist/modules/Date/index.js +5 -1
- package/dist/modules/Discount/index.d.ts +0 -1
- package/dist/modules/Discount/index.js +7 -22
- package/dist/modules/Discount/types.d.ts +0 -1
- package/dist/modules/OpenData/index.js +2 -0
- package/dist/modules/Order/index.js +70 -40
- package/dist/modules/Payment/index.js +162 -97
- package/dist/modules/Payment/types.d.ts +4 -8
- package/dist/modules/Payment/walletpass.d.ts +0 -2
- package/dist/modules/Payment/walletpass.js +5 -4
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +3 -12
- package/dist/modules/ProductList/types.d.ts +0 -1
- package/dist/modules/Rules/index.js +126 -427
- package/dist/modules/SalesSummary/utils.js +1 -2
- package/dist/modules/Schedule/getDateIsInSchedule.js +0 -5
- package/dist/modules/Schedule/index.js +1 -0
- package/dist/modules/Schedule/utils.js +1 -0
- package/dist/modules/Step/index.js +1 -0
- package/dist/modules/Summary/utils.js +22 -43
- package/dist/plugins/request.js +4 -1
- package/dist/plugins/window.js +6 -2
- package/dist/server/index.js +129 -97
- package/dist/server/modules/menu/index.js +41 -32
- package/dist/server/modules/order/index.js +4 -2
- package/dist/server/modules/products/index.js +42 -24
- package/dist/server/modules/quotation/index.js +38 -29
- package/dist/server/modules/resource/index.js +4 -3
- package/dist/server/modules/schedule/index.js +35 -27
- package/dist/server/utils/product.js +1 -0
- package/dist/solution/BaseSales/index.js +41 -38
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +60 -11
- package/dist/solution/BookingByStep/utils/capacity.js +11 -1
- package/dist/solution/BookingByStep/utils/resources.js +3 -1
- package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +2 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +7 -6
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +31 -25
- package/dist/solution/BookingTicket/utils/scan/index.js +10 -6
- package/dist/solution/BuyTickets/index.js +12 -9
- package/dist/solution/Checkout/index.js +252 -177
- package/dist/solution/Checkout/utils/index.js +16 -4
- package/dist/solution/RegisterAndLogin/index.js +76 -30
- package/dist/solution/ScanOrder/index.js +60 -50
- package/dist/solution/ShopDiscount/index.js +14 -15
- package/dist/solution/ShopDiscount/types.d.ts +4 -5
- package/dist/solution/ShopDiscount/utils.d.ts +0 -9
- package/dist/solution/ShopDiscount/utils.js +0 -9
- package/dist/solution/VenueBooking/index.d.ts +3 -31
- package/dist/solution/VenueBooking/index.js +496 -651
- package/dist/solution/VenueBooking/types.d.ts +1 -3
- package/dist/solution/VenueBooking/types.js +0 -1
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
- package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/task.js +18 -15
- package/dist/utils/watch.js +1 -0
- package/lib/apis/picoding.js +0 -2
- package/lib/core/index.js +132 -130
- package/lib/effects/index.js +57 -46
- package/lib/index.d.ts +0 -1
- package/lib/index.js +50 -92
- package/lib/model/index.js +21 -14
- package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
- package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
- package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
- package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
- package/lib/model/strategy/adapter/index.js +64 -100
- package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
- package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
- package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
- package/lib/model/strategy/adapter/itemRule/index.js +57 -83
- package/lib/model/strategy/adapter/itemRule/type.js +36 -97
- package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
- package/lib/model/strategy/adapter/promotion/evaluator.js +231 -381
- package/lib/model/strategy/adapter/promotion/examples.js +159 -139
- package/lib/model/strategy/adapter/promotion/index.js +49 -1
- package/lib/model/strategy/adapter/promotion/type.js +35 -199
- package/lib/model/strategy/adapter/type.js +16 -4
- package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
- package/lib/model/strategy/adapter/walletPass/example.js +190 -217
- package/lib/model/strategy/adapter/walletPass/index.js +51 -75
- package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
- package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
- package/lib/model/strategy/adapter/walletPass/type.js +16 -4
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
- package/lib/model/strategy/adapter/walletPass/utils.js +383 -678
- package/lib/model/strategy/engine.js +168 -270
- package/lib/model/strategy/index.js +34 -49
- package/lib/model/strategy/strategy-example.js +239 -243
- package/lib/model/strategy/type.js +40 -100
- package/lib/modules/Account/index.js +53 -39
- package/lib/modules/Account/types.js +33 -20
- package/lib/modules/AccountList/index.js +154 -116
- package/lib/modules/AccountList/types.js +31 -30
- package/lib/modules/AccountList/utils.js +30 -18
- package/lib/modules/BaseModule.d.ts +1 -1
- package/lib/modules/BaseModule.js +46 -25
- package/lib/modules/BookingContext/index.js +136 -158
- package/lib/modules/BookingContext/types.js +32 -46
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +143 -131
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +82 -75
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +150 -170
- package/lib/modules/BookingContext/utils/flexible.js +55 -38
- package/lib/modules/BookingContext/utils/formatResourceList.js +34 -19
- package/lib/modules/BookingContext/utils/index.js +41 -124
- package/lib/modules/BookingContext/utils/noResource.js +70 -58
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +41 -14
- package/lib/modules/BookingContext/utils/productExtend.js +155 -202
- package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
- package/lib/modules/BookingContext/utils/resourceSelection.js +41 -19
- package/lib/modules/BookingContext/utils/resources.js +167 -209
- package/lib/modules/BookingContext/utils/serviceTimes.js +116 -115
- package/lib/modules/BookingContext/utils/timeSlices.js +80 -70
- package/lib/modules/Cart/index.js +124 -170
- package/lib/modules/Cart/types.js +51 -46
- package/lib/modules/Cart/utils/cartAccount.js +39 -40
- package/lib/modules/Cart/utils/cartDate.js +61 -56
- package/lib/modules/Cart/utils/cartDiscount.js +33 -28
- package/lib/modules/Cart/utils/cartNote.js +32 -27
- package/lib/modules/Cart/utils/cartProduct.js +251 -321
- package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
- package/lib/modules/Cart/utils/cartResource.js +78 -72
- package/lib/modules/Cart/utils/changePrice.js +50 -28
- package/lib/modules/Cart/utils/index.js +48 -106
- package/lib/modules/Customer/constants.js +34 -13
- package/lib/modules/Customer/index.js +169 -232
- package/lib/modules/Customer/types.js +35 -38
- package/lib/modules/Date/index.js +115 -116
- package/lib/modules/Date/types.js +28 -16
- package/lib/modules/Date/utils.js +123 -174
- package/lib/modules/Discount/index.d.ts +0 -1
- package/lib/modules/Discount/index.js +128 -130
- package/lib/modules/Discount/types.d.ts +0 -1
- package/lib/modules/Discount/types.js +31 -9
- package/lib/modules/Guests/index.js +56 -30
- package/lib/modules/Guests/types.js +33 -23
- package/lib/modules/Holder/index.js +189 -209
- package/lib/modules/Holder/types.js +16 -4
- package/lib/modules/Holder/utils.js +49 -20
- package/lib/modules/OpenData/index.js +76 -69
- package/lib/modules/OpenData/types.js +16 -4
- package/lib/modules/OpenData/utils.js +78 -44
- package/lib/modules/Order/index.js +1909 -1572
- package/lib/modules/Order/types.js +35 -78
- package/lib/modules/Order/utils/bundleDiscountHydration.js +74 -41
- package/lib/modules/Order/utils/manualProductDiscount.js +123 -124
- package/lib/modules/Order/utils/orderCollectionIdentity.js +210 -148
- package/lib/modules/Order/utils.js +634 -799
- package/lib/modules/Payment/cash.js +33 -20
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
- package/lib/modules/Payment/eftpos.js +30 -16
- package/lib/modules/Payment/index.js +378 -518
- package/lib/modules/Payment/mx51.js +0 -1
- package/lib/modules/Payment/types.d.ts +4 -8
- package/lib/modules/Payment/types.js +107 -216
- package/lib/modules/Payment/utils.js +48 -51
- package/lib/modules/Payment/walletpass.d.ts +0 -2
- package/lib/modules/Payment/walletpass.js +211 -226
- package/lib/modules/Product/index.js +46 -51
- package/lib/modules/Product/types.js +16 -4
- package/lib/modules/Product/utils.js +33 -32
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +117 -117
- package/lib/modules/ProductList/types.d.ts +0 -1
- package/lib/modules/ProductList/types.js +31 -9
- package/lib/modules/Quotation/index.js +100 -66
- package/lib/modules/Quotation/types.js +16 -4
- package/lib/modules/Resource/index.js +59 -27
- package/lib/modules/Resource/types.js +32 -22
- package/lib/modules/Resource/utils.js +38 -30
- package/lib/modules/ResourcePlanner/index.js +61 -60
- package/lib/modules/ResourcePlanner/planner.js +384 -346
- package/lib/modules/ResourcePlanner/types.js +16 -4
- package/lib/modules/Rules/index.js +903 -1475
- package/lib/modules/Rules/types.js +40 -17
- package/lib/modules/SalesSummary/index.js +90 -85
- package/lib/modules/SalesSummary/types.js +16 -4
- package/lib/modules/SalesSummary/utils.js +427 -351
- package/lib/modules/ScanOrderLogger/index.js +79 -59
- package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
- package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
- package/lib/modules/ScanOrderLogger/types.js +16 -4
- package/lib/modules/Schedule/getDateIsInSchedule.js +163 -339
- package/lib/modules/Schedule/index.js +114 -100
- package/lib/modules/Schedule/type.js +16 -4
- package/lib/modules/Schedule/types.js +16 -4
- package/lib/modules/Schedule/utils.js +291 -433
- package/lib/modules/Step/index.js +52 -40
- package/lib/modules/Step/tyeps.js +16 -4
- package/lib/modules/Summary/index.js +71 -66
- package/lib/modules/Summary/types.js +16 -4
- package/lib/modules/Summary/utils.js +418 -791
- package/lib/modules/SurchargeList/index.js +60 -46
- package/lib/modules/SurchargeList/types.js +16 -4
- package/lib/modules/index.js +63 -245
- package/lib/plugins/app.js +16 -4
- package/lib/plugins/index.js +25 -36
- package/lib/plugins/request.js +126 -137
- package/lib/plugins/shopStore.js +16 -4
- package/lib/plugins/user.js +16 -4
- package/lib/plugins/window.js +179 -171
- package/lib/server/index.js +2337 -2675
- package/lib/server/modules/floor-plan/index.js +123 -102
- package/lib/server/modules/floor-plan/types.js +30 -15
- package/lib/server/modules/index.js +68 -106
- package/lib/server/modules/menu/index.js +122 -146
- package/lib/server/modules/menu/types.js +31 -18
- package/lib/server/modules/order/index.js +642 -567
- package/lib/server/modules/order/types.js +32 -117
- package/lib/server/modules/order/utils/filterBookings.js +194 -219
- package/lib/server/modules/order/utils/filterOrders.js +92 -118
- package/lib/server/modules/payment/index.js +83 -59
- package/lib/server/modules/payment/types.js +16 -4
- package/lib/server/modules/products/index.js +459 -575
- package/lib/server/modules/products/types.js +34 -44
- package/lib/server/modules/quotation/index.js +172 -137
- package/lib/server/modules/quotation/types.js +31 -21
- package/lib/server/modules/resource/index.js +184 -213
- package/lib/server/modules/resource/types.js +33 -42
- package/lib/server/modules/schedule/index.js +123 -135
- package/lib/server/modules/schedule/types.js +21 -14
- package/lib/server/modules/schedule/utils.js +163 -334
- package/lib/server/types.js +16 -4
- package/lib/server/utils/index.js +23 -25
- package/lib/server/utils/product.js +139 -196
- package/lib/server/utils/schedule.js +41 -34
- package/lib/server/utils/small-ticket.js +456 -478
- package/lib/server/utils/time.js +49 -40
- package/lib/solution/BaseSales/index.js +1016 -850
- package/lib/solution/BaseSales/types.js +37 -41
- package/lib/solution/BaseSales/utils/cartPromotion.js +460 -611
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +105 -85
- package/lib/solution/BaseSales/utils/quotationPrice.js +114 -56
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +143 -102
- package/lib/solution/BaseSales/utils.js +140 -155
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +1340 -1530
- package/lib/solution/BookingByStep/types.js +99 -40
- package/lib/solution/BookingByStep/utils/capacity.js +160 -192
- package/lib/solution/BookingByStep/utils/products.js +52 -42
- package/lib/solution/BookingByStep/utils/resources.js +330 -527
- package/lib/solution/BookingByStep/utils/stock.js +44 -65
- package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +459 -543
- package/lib/solution/BookingTicket/types.js +77 -99
- package/lib/solution/BookingTicket/utils/addProductDecision.js +184 -219
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +89 -58
- package/lib/solution/BookingTicket/utils/bookingStatus.js +78 -107
- package/lib/solution/BookingTicket/utils/cartView.js +94 -110
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -185
- package/lib/solution/BookingTicket/utils/orderCustomer.js +41 -18
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +86 -219
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +93 -144
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +91 -79
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +41 -54
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -84
- package/lib/solution/BookingTicket/utils/scan/index.js +104 -98
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +64 -52
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +58 -56
- package/lib/solution/BuyTickets/index.js +70 -67
- package/lib/solution/BuyTickets/types.js +38 -22
- package/lib/solution/Checkout/index.js +1158 -1451
- package/lib/solution/Checkout/types.js +61 -91
- package/lib/solution/Checkout/utils/index.js +156 -228
- package/lib/solution/PlaceOrder/index.js +0 -55
- package/lib/solution/RegisterAndLogin/config.js +460 -493
- package/lib/solution/RegisterAndLogin/index.js +630 -633
- package/lib/solution/RegisterAndLogin/types.js +76 -189
- package/lib/solution/RegisterAndLogin/utils.js +125 -183
- package/lib/solution/Sales/index.js +320 -317
- package/lib/solution/Sales/types.js +33 -27
- package/lib/solution/ScanOrder/index.js +862 -831
- package/lib/solution/ScanOrder/types.js +34 -33
- package/lib/solution/ScanOrder/utils.js +371 -406
- package/lib/solution/ShopDiscount/index.js +233 -235
- package/lib/solution/ShopDiscount/types.d.ts +4 -5
- package/lib/solution/ShopDiscount/types.js +37 -15
- package/lib/solution/ShopDiscount/utils.d.ts +0 -9
- package/lib/solution/ShopDiscount/utils.js +172 -309
- package/lib/solution/UnifiedBookingSales/index.js +405 -379
- package/lib/solution/UnifiedBookingSales/types.js +31 -12
- package/lib/solution/VenueBooking/index.d.ts +3 -31
- package/lib/solution/VenueBooking/index.js +916 -967
- package/lib/solution/VenueBooking/types.d.ts +1 -3
- package/lib/solution/VenueBooking/types.js +39 -20
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
- package/lib/solution/VenueBooking/utils/resource.js +54 -31
- package/lib/solution/VenueBooking/utils/slotMerge.js +107 -94
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
- package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
- package/lib/solution/VenueBooking/utils.js +67 -130
- package/lib/solution/index.js +41 -124
- package/lib/store/createStore.js +29 -32
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.js +16 -4
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +47 -81
- package/package.json +2 -4
- package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
- package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
- package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
- package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
|
@@ -665,14 +665,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
665
665
|
}
|
|
666
666
|
});
|
|
667
667
|
}
|
|
668
|
-
// 检查商品是否被排除(全品类)
|
|
669
|
-
var isProductIncludedByLimitedData = function isProductIncludedByLimitedData(limitedData, productId) {
|
|
670
|
-
var excludedIds = (limitedData === null || limitedData === void 0 ? void 0 : limitedData.exclude_product_ids) || [];
|
|
671
|
-
var isExcluded = (limitedData === null || limitedData === void 0 ? void 0 : limitedData.filter) === 1 && excludedIds.some(function (id) {
|
|
672
|
-
return String(id) === String(productId);
|
|
673
|
-
});
|
|
674
|
-
return !isExcluded;
|
|
675
|
-
};
|
|
676
668
|
|
|
677
669
|
/**
|
|
678
670
|
// 对productList按价格降序排序(用于应用优惠券时优先选择高价商品) 价格相同时使用quantity 排序
|
|
@@ -697,19 +689,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
697
689
|
// 🔥 统计每个 product_id(商品券商品id)已使用的数量,用于 maxUsagePerOrder 限制
|
|
698
690
|
var usedProductIdCounts = new Map();
|
|
699
691
|
|
|
700
|
-
// 🔥 统计每张折扣卡的 applicableProductLimit 已使用次数(跨商品全局计数)
|
|
701
|
-
var usedDiscountCardLimitCounts = new Map();
|
|
702
|
-
|
|
703
|
-
// 🔥 预先将 editModeDiscount 中的折扣卡计入 applicableProductLimit 已使用次数
|
|
704
|
-
editModeDiscount.forEach(function (discount) {
|
|
705
|
-
var discountType = discount.tag || discount.type;
|
|
706
|
-
if (['discount_card', 'product_discount_card'].includes(discountType)) {
|
|
707
|
-
var _discount$metadata4;
|
|
708
|
-
var currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
|
|
709
|
-
usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.num) || 1));
|
|
710
|
-
}
|
|
711
|
-
});
|
|
712
|
-
|
|
713
692
|
// 记录每个优惠券适用的商品ID
|
|
714
693
|
var discountApplicability = new Map();
|
|
715
694
|
|
|
@@ -924,7 +903,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
924
903
|
var _flatItem$parentProdu5;
|
|
925
904
|
// bundle子商品:构造虚拟商品对象
|
|
926
905
|
product = {
|
|
927
|
-
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate,
|
|
928
906
|
_id: flatItem._id,
|
|
929
907
|
id: flatItem.id,
|
|
930
908
|
price: flatItem.price,
|
|
@@ -933,7 +911,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
933
911
|
total: flatItem.total,
|
|
934
912
|
origin_total: flatItem.origin_total,
|
|
935
913
|
booking_id: flatItem.booking_id,
|
|
936
|
-
discount_list: flatItem.discount_list || []
|
|
914
|
+
discount_list: flatItem.discount_list || [],
|
|
915
|
+
startDate: (_flatItem$parentProdu5 = flatItem.parentProduct) === null || _flatItem$parentProdu5 === void 0 ? void 0 : _flatItem$parentProdu5.startDate
|
|
937
916
|
};
|
|
938
917
|
originProduct = flatItem.originProduct;
|
|
939
918
|
}
|
|
@@ -963,7 +942,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
963
942
|
|
|
964
943
|
// 判断优惠券是否适用于该商品
|
|
965
944
|
if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && (_discount$config = discount.config) !== null && _discount$config !== void 0 && _discount$config.isAvailable) {
|
|
966
|
-
var _discountApplicabilit, _discount$
|
|
945
|
+
var _discountApplicabilit, _discount$metadata4, _discount$metadata5;
|
|
967
946
|
// 记录此优惠券适用的商品
|
|
968
947
|
(_discountApplicabilit = discountApplicability.get(discount.id)) === null || _discountApplicabilit === void 0 || _discountApplicabilit.push(product.id);
|
|
969
948
|
|
|
@@ -979,9 +958,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
979
958
|
type: discountType,
|
|
980
959
|
tag: discountType,
|
|
981
960
|
discount: {
|
|
982
|
-
discount_card_type: discount === null || discount === void 0 || (_discount$
|
|
961
|
+
discount_card_type: discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_card_type,
|
|
983
962
|
fixed_amount: product.price,
|
|
984
|
-
discount_calculation_mode: discount === null || discount === void 0 || (_discount$
|
|
963
|
+
discount_calculation_mode: discount === null || discount === void 0 || (_discount$metadata5 = discount.metadata) === null || _discount$metadata5 === void 0 ? void 0 : _discount$metadata5.discount_calculation_mode,
|
|
985
964
|
resource_id: discount.id,
|
|
986
965
|
title: discount.format_title,
|
|
987
966
|
original_amount: product.price || product.origin_total,
|
|
@@ -1061,17 +1040,16 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1061
1040
|
// 然后再处理应用哪些优惠券,此时只考虑filteredDiscountList中的优惠券
|
|
1062
1041
|
// 🔥 使用扁平化后的列表进行处理
|
|
1063
1042
|
sortedFlattenedList.forEach(function (flatItem, index) {
|
|
1064
|
-
var _product10, _originProduct, _originProduct2, _originProduct3, _product$discount_lis2, _product11
|
|
1043
|
+
var _product10, _originProduct, _originProduct2, _originProduct3, _product$discount_lis2, _product11;
|
|
1065
1044
|
// 获取商品数据
|
|
1066
1045
|
var product, originProduct;
|
|
1067
1046
|
if (flatItem.type === 'main') {
|
|
1068
1047
|
product = flatItem.product;
|
|
1069
1048
|
originProduct = flatItem.originProduct;
|
|
1070
1049
|
} else {
|
|
1071
|
-
var _flatItem$
|
|
1050
|
+
var _flatItem$bundleItem5, _flatItem$bundleItem6, _flatItem$bundleItem7, _flatItem$parentProdu6;
|
|
1072
1051
|
// bundle子商品
|
|
1073
1052
|
product = {
|
|
1074
|
-
startDate: flatItem === null || flatItem === void 0 || (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate,
|
|
1075
1053
|
_id: flatItem._id,
|
|
1076
1054
|
id: flatItem.id,
|
|
1077
1055
|
price: flatItem.price,
|
|
@@ -1081,7 +1059,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1081
1059
|
original_price: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem5 = flatItem.bundleItem) === null || _flatItem$bundleItem5 === void 0 ? void 0 : _flatItem$bundleItem5.original_price,
|
|
1082
1060
|
origin_total: flatItem === null || flatItem === void 0 || (_flatItem$bundleItem6 = flatItem.bundleItem) === null || _flatItem$bundleItem6 === void 0 ? void 0 : _flatItem$bundleItem6.original_price,
|
|
1083
1061
|
booking_id: flatItem.booking_id,
|
|
1084
|
-
discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || []
|
|
1062
|
+
discount_list: (flatItem === null || flatItem === void 0 || (_flatItem$bundleItem7 = flatItem.bundleItem) === null || _flatItem$bundleItem7 === void 0 ? void 0 : _flatItem$bundleItem7.discount_list) || [],
|
|
1063
|
+
startDate: (_flatItem$parentProdu6 = flatItem.parentProduct) === null || _flatItem$parentProdu6 === void 0 ? void 0 : _flatItem$parentProdu6.startDate
|
|
1085
1064
|
};
|
|
1086
1065
|
originProduct = flatItem.originProduct;
|
|
1087
1066
|
}
|
|
@@ -1149,19 +1128,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1149
1128
|
}
|
|
1150
1129
|
}
|
|
1151
1130
|
}
|
|
1152
|
-
|
|
1153
|
-
// 🔥 检查折扣卡的 applicableProductLimit 限制:折扣卡可使用的最大次数(跨商品全局)
|
|
1154
|
-
var discountTypeForLimit = discount.tag || discount.type;
|
|
1155
|
-
if (['discount_card', 'product_discount_card'].includes(discountTypeForLimit)) {
|
|
1156
|
-
var _discount$config4;
|
|
1157
|
-
var applicableProductLimitConfig = ((_discount$config4 = discount.config) === null || _discount$config4 === void 0 ? void 0 : _discount$config4.applicableProductLimit) || 0;
|
|
1158
|
-
if (applicableProductLimitConfig > 0) {
|
|
1159
|
-
var currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
|
|
1160
|
-
if (currentUsedLimitCount >= applicableProductLimitConfig) {
|
|
1161
|
-
return false;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
1131
|
var limitedData = discount.limited_relation_product_data;
|
|
1166
1132
|
|
|
1167
1133
|
// 拿到discount配置的holder信息 product信息 product.holder 不可用return false
|
|
@@ -1180,10 +1146,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1180
1146
|
|
|
1181
1147
|
// 判断优惠券是否适用于该商品
|
|
1182
1148
|
if (limitedData.type === 'product_all') {
|
|
1183
|
-
if (
|
|
1149
|
+
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
1184
1150
|
return false;
|
|
1185
1151
|
}
|
|
1186
|
-
|
|
1187
1152
|
// 检查 package_sub_item_usage_rules
|
|
1188
1153
|
if (!_this3.checkPackageSubItemUsageRules(discount, flatItem)) {
|
|
1189
1154
|
return false;
|
|
@@ -1325,9 +1290,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1325
1290
|
discount_list: isManualDiscount ? _this3.resolveDiscountListForManualOverride(product.discount_list) : _this3.filterDiscountListByType(product.discount_list, 'promotion')
|
|
1326
1291
|
}))]);
|
|
1327
1292
|
} else {
|
|
1328
|
-
var _ref13, _product$_promotion$f, _product13, _product$origin_total
|
|
1293
|
+
var _ref13, _product$_promotion$f, _product13, _product$origin_total;
|
|
1329
1294
|
var total = product.inPromotion ? (_ref13 = (_product$_promotion$f = (_product13 = product) === null || _product13 === void 0 || (_product13 = _product13._promotion) === null || _product13 === void 0 ? void 0 : _product13.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref13 !== void 0 ? _ref13 : product.total : (_product$origin_total = product.origin_total) !== null && _product$origin_total !== void 0 ? _product$origin_total : product.total;
|
|
1330
|
-
var main_product_selling_price =
|
|
1295
|
+
var main_product_selling_price = product.price;
|
|
1331
1296
|
if ((product.discount_list || []).some(function (item) {
|
|
1332
1297
|
return item.type === 'promotion';
|
|
1333
1298
|
}) || isBoolean(product.vouchersApplicable) && !product.vouchersApplicable) {
|
|
@@ -1363,14 +1328,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1363
1328
|
return;
|
|
1364
1329
|
}
|
|
1365
1330
|
|
|
1366
|
-
//
|
|
1367
|
-
var
|
|
1368
|
-
var isGoodPass = discountType === 'good_pass';
|
|
1369
|
-
var isDiscountCard = ['discount_card', 'product_discount_card'].includes(discountType);
|
|
1370
|
-
var applicableProductLimit = ((_selectedDiscount$con = selectedDiscount.config) === null || _selectedDiscount$con === void 0 ? void 0 : _selectedDiscount$con.applicableProductLimit) || 0;
|
|
1371
|
-
|
|
1372
|
-
// 商品券始终需要拆分,折扣卡在 applicableProductLimit > 0 时需要拆分
|
|
1373
|
-
var isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
|
|
1331
|
+
// 是否需要拆分(商品券需要拆分)
|
|
1332
|
+
var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
|
|
1374
1333
|
|
|
1375
1334
|
// 需要拆分出来的数量
|
|
1376
1335
|
var totalQuantity = product.quantity || product.num || 1;
|
|
@@ -1378,22 +1337,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1378
1337
|
return (item.tag || item.type) === 'good_pass';
|
|
1379
1338
|
}).length;
|
|
1380
1339
|
|
|
1381
|
-
// 🔥
|
|
1382
|
-
var maxUsageLimit;
|
|
1383
|
-
if (
|
|
1384
|
-
|
|
1385
|
-
maxUsageLimit = availableGoodPassCount;
|
|
1386
|
-
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
1387
|
-
maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
|
|
1388
|
-
}
|
|
1389
|
-
} else if (isDiscountCard && applicableProductLimit > 0) {
|
|
1390
|
-
// 折扣卡:使用 applicableProductLimit 限制(一个商品使用一次折扣卡算1次)
|
|
1391
|
-
// 需要减去已使用次数(跨商品全局计数)
|
|
1392
|
-
var usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
|
|
1393
|
-
maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
|
|
1394
|
-
} else {
|
|
1395
|
-
// 其他情况不拆分
|
|
1396
|
-
maxUsageLimit = 1;
|
|
1340
|
+
// 🔥 如果selectedDiscount有config配置,则使用config.maxUsagePerOrder限制使用次数
|
|
1341
|
+
var maxUsageLimit = availableGoodPassCount;
|
|
1342
|
+
if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
|
|
1343
|
+
maxUsageLimit = Math.min(availableGoodPassCount, selectedDiscount.config.maxUsagePerOrder);
|
|
1397
1344
|
}
|
|
1398
1345
|
var splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
|
|
1399
1346
|
var arr = [];
|
|
@@ -1418,26 +1365,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1418
1365
|
}));
|
|
1419
1366
|
}
|
|
1420
1367
|
for (var i = 0; i < splitCount; i++) {
|
|
1421
|
-
var _originProduct4, _selectedDiscount$
|
|
1422
|
-
//
|
|
1423
|
-
|
|
1424
|
-
var currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
|
|
1368
|
+
var _originProduct4, _selectedDiscount$con, _product$options, _product$options2, _selectedDiscount$met, _selectedDiscount$met2, _reapplyDiscountPerce;
|
|
1369
|
+
// 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
|
|
1370
|
+
var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
|
|
1425
1371
|
// 标记优惠券为已使用
|
|
1426
|
-
usedDiscounts.set(
|
|
1372
|
+
usedDiscounts.set(_selectedDiscount.id, true);
|
|
1427
1373
|
// 🔥 更新 product_id 使用计数
|
|
1428
|
-
if ((
|
|
1429
|
-
var currentCount = usedProductIdCounts.get(
|
|
1430
|
-
usedProductIdCounts.set(
|
|
1431
|
-
}
|
|
1432
|
-
// 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
|
|
1433
|
-
var currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
|
|
1434
|
-
if (['discount_card', 'product_discount_card'].includes(currentDiscountTypeForCount)) {
|
|
1435
|
-
var currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
|
|
1436
|
-
usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
|
|
1374
|
+
if ((_selectedDiscount.tag || _selectedDiscount.type) === 'good_pass') {
|
|
1375
|
+
var currentCount = usedProductIdCounts.get(_selectedDiscount.product_id) || 0;
|
|
1376
|
+
usedProductIdCounts.set(_selectedDiscount.product_id, currentCount + 1);
|
|
1437
1377
|
}
|
|
1438
1378
|
|
|
1439
1379
|
// 记录实际应用了优惠券的商品信息
|
|
1440
|
-
var appliedProducts = appliedDiscountProducts.get(
|
|
1380
|
+
var appliedProducts = appliedDiscountProducts.get(_selectedDiscount.id) || [];
|
|
1441
1381
|
|
|
1442
1382
|
// 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
|
|
1443
1383
|
var productOriginTotal = product.origin_total || product.total || 0;
|
|
@@ -1452,10 +1392,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1452
1392
|
|
|
1453
1393
|
// 计算使用折扣卡/商品券以后,单个商品的总 total
|
|
1454
1394
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1455
|
-
var isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1456
|
-
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1395
|
+
var isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount);
|
|
1396
|
+
var orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount.id) : null;
|
|
1457
1397
|
var productAllocation = orderLevelAllocation === null || orderLevelAllocation === void 0 ? void 0 : orderLevelAllocation.get(flatItem._id);
|
|
1458
|
-
var isDeductOptionPrice = !!((_selectedDiscount$
|
|
1398
|
+
var isDeductOptionPrice = !!((_selectedDiscount$con = _selectedDiscount.config) !== null && _selectedDiscount$con !== void 0 && _selectedDiscount$con.deductOptionPrice);
|
|
1459
1399
|
|
|
1460
1400
|
// 主商品折后价(不含 option);勿与 option 合计混在同一变量,否则 main_product_selling_price 错误
|
|
1461
1401
|
var mainProductSellingPrice = void 0;
|
|
@@ -1469,19 +1409,19 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1469
1409
|
amount = productAllocation.discountAmount;
|
|
1470
1410
|
productDiscountDifference = productAllocation.difference;
|
|
1471
1411
|
mainProductSellingPrice = Math.max(new Decimal(product.price).minus(amount).toNumber(), 0);
|
|
1472
|
-
} else if (resolveReapplyEditModeDiscountPercent(originProduct,
|
|
1412
|
+
} else if (resolveReapplyEditModeDiscountPercent(originProduct, _selectedDiscount) !== undefined) {
|
|
1473
1413
|
// Change time 重套编辑态折扣卡时,历史 par_value 不是运行时折扣口径,优先使用后端快照里的 percent。
|
|
1474
|
-
var percent = resolveReapplyEditModeDiscountPercent(originProduct,
|
|
1414
|
+
var percent = resolveReapplyEditModeDiscountPercent(originProduct, _selectedDiscount);
|
|
1475
1415
|
reapplyDiscountPercent = new Decimal(percent).toFixed(2);
|
|
1476
1416
|
mainProductSellingPrice = new Decimal(product.price || 0).mul(new Decimal(100).minus(percent)).div(100).toDecimalPlaces(2).toNumber();
|
|
1477
1417
|
amount = new Decimal(product.price).minus(mainProductSellingPrice).toNumber();
|
|
1478
1418
|
} else {
|
|
1479
1419
|
// item_level 或其他类型:使用原有逻辑
|
|
1480
|
-
mainProductSellingPrice = getDiscountAmount(
|
|
1420
|
+
mainProductSellingPrice = getDiscountAmount(_selectedDiscount, product.price, product.price);
|
|
1481
1421
|
amount = new Decimal(product.price).minus(new Decimal(mainProductSellingPrice)).toNumber();
|
|
1482
1422
|
}
|
|
1483
1423
|
if (isDeductOptionPrice && (_product$options = product.options) !== null && _product$options !== void 0 && _product$options.length) {
|
|
1484
|
-
var optionResult = applyDiscountToOptions(product.options,
|
|
1424
|
+
var optionResult = applyDiscountToOptions(product.options, _selectedDiscount);
|
|
1485
1425
|
discountedOptions = optionResult.discountedOptions;
|
|
1486
1426
|
optionDiscountAmount = optionResult.optionDiscountAmount;
|
|
1487
1427
|
}
|
|
@@ -1494,28 +1434,28 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1494
1434
|
// discount_list.amount / fixed_amount:行级总优惠 = 主商品优惠 + option 优惠(与 total 变化一致)
|
|
1495
1435
|
var mainProductDiscountAmount = amount;
|
|
1496
1436
|
var lineDiscountAmount = new Decimal(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
|
|
1497
|
-
var
|
|
1498
|
-
var
|
|
1437
|
+
var discountType = _selectedDiscount.tag || _selectedDiscount.type;
|
|
1438
|
+
var isGoodPass = discountType === 'good_pass';
|
|
1499
1439
|
var discountDetail = {
|
|
1500
1440
|
amount: lineDiscountAmount,
|
|
1501
|
-
type:
|
|
1441
|
+
type: _selectedDiscount.tag === 'product_discount_card' ? 'discount_card' : discountType,
|
|
1502
1442
|
discount: {
|
|
1503
|
-
discount_card_type:
|
|
1443
|
+
discount_card_type: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met = _selectedDiscount.metadata) === null || _selectedDiscount$met === void 0 ? void 0 : _selectedDiscount$met.discount_card_type,
|
|
1504
1444
|
fixed_amount: lineDiscountAmount,
|
|
1505
|
-
discount_calculation_mode:
|
|
1506
|
-
resource_id:
|
|
1507
|
-
title:
|
|
1445
|
+
discount_calculation_mode: _selectedDiscount === null || _selectedDiscount === void 0 || (_selectedDiscount$met2 = _selectedDiscount.metadata) === null || _selectedDiscount$met2 === void 0 ? void 0 : _selectedDiscount$met2.discount_calculation_mode,
|
|
1446
|
+
resource_id: _selectedDiscount.id,
|
|
1447
|
+
title: _selectedDiscount.format_title,
|
|
1508
1448
|
original_amount: product.price,
|
|
1509
1449
|
product_id: originProduct.id || originProduct.product_id,
|
|
1510
|
-
percent: (_reapplyDiscountPerce = reapplyDiscountPercent) !== null && _reapplyDiscountPerce !== void 0 ? _reapplyDiscountPerce :
|
|
1511
|
-
discount_product_id:
|
|
1450
|
+
percent: (_reapplyDiscountPerce = reapplyDiscountPercent) !== null && _reapplyDiscountPerce !== void 0 ? _reapplyDiscountPerce : _selectedDiscount.par_value,
|
|
1451
|
+
discount_product_id: _selectedDiscount.product_id
|
|
1512
1452
|
},
|
|
1513
|
-
// 前端使用的num
|
|
1514
|
-
_num:
|
|
1515
|
-
config:
|
|
1453
|
+
// 前端使用的num数量,为了计算优惠金额
|
|
1454
|
+
_num: isGoodPass ? 1 : product.num,
|
|
1455
|
+
config: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.config,
|
|
1516
1456
|
metadata: _objectSpread(_objectSpread({
|
|
1517
1457
|
num: 1,
|
|
1518
|
-
discount_rule_uncheck_flag:
|
|
1458
|
+
discount_rule_uncheck_flag: _selectedDiscount === null || _selectedDiscount === void 0 ? void 0 : _selectedDiscount.discount_rule_uncheck_flag
|
|
1519
1459
|
}, productDiscountDifference !== undefined && {
|
|
1520
1460
|
product_discount_difference: productDiscountDifference
|
|
1521
1461
|
}), {}, {
|
|
@@ -1525,7 +1465,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1525
1465
|
})
|
|
1526
1466
|
};
|
|
1527
1467
|
appliedProducts.push(discountDetail);
|
|
1528
|
-
appliedDiscountProducts.set(
|
|
1468
|
+
appliedDiscountProducts.set(_selectedDiscount.id, appliedProducts);
|
|
1529
1469
|
|
|
1530
1470
|
// 记录应用了优惠券的商品
|
|
1531
1471
|
// 后续更新价格改为 getProductTotalPrice getProductOriginTotalPrice逻辑
|
|
@@ -1550,8 +1490,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1550
1490
|
} else {
|
|
1551
1491
|
arr.push(_this3.hooks.setProduct(originProduct, {
|
|
1552
1492
|
discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
|
|
1553
|
-
_id: product._id.split('___')[0] + '___' +
|
|
1554
|
-
price:
|
|
1493
|
+
_id: product._id.split('___')[0] + '___' + _selectedDiscount.id + index,
|
|
1494
|
+
price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
|
|
1555
1495
|
quantity: isNeedSplit ? 1 : product.quantity,
|
|
1556
1496
|
total: _total2,
|
|
1557
1497
|
origin_total: productOriginTotal,
|
|
@@ -1562,69 +1502,57 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1562
1502
|
}
|
|
1563
1503
|
processedProductsMap.set(product._id, arr);
|
|
1564
1504
|
} else {
|
|
1565
|
-
// 🔥 bundle
|
|
1505
|
+
// 🔥 bundle子商品:支持拆分
|
|
1566
1506
|
var processedItems = [];
|
|
1567
1507
|
if (isNeedSplit) {
|
|
1568
|
-
//
|
|
1508
|
+
// 商品券:需要拆分数量
|
|
1569
1509
|
var discountNum = splitCount;
|
|
1570
1510
|
var normalNum = totalQuantity - discountNum;
|
|
1571
1511
|
|
|
1572
|
-
//
|
|
1512
|
+
// 生成有折扣的商品(每张商品券对应 num: 1)
|
|
1573
1513
|
for (var _i = 0; _i < discountNum; _i++) {
|
|
1574
|
-
var
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
var currentBundleDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[_i] : selectedDiscountCard || applicableDiscounts[0];
|
|
1578
|
-
usedDiscounts.set(currentBundleDiscount.id, true);
|
|
1514
|
+
var _selectedDiscount2$me;
|
|
1515
|
+
var _selectedDiscount2 = applicableDiscounts[_i];
|
|
1516
|
+
usedDiscounts.set(_selectedDiscount2.id, true);
|
|
1579
1517
|
// 🔥 更新 product_id 使用计数
|
|
1580
|
-
if ((
|
|
1581
|
-
var _currentCount = usedProductIdCounts.get(
|
|
1582
|
-
usedProductIdCounts.set(
|
|
1583
|
-
}
|
|
1584
|
-
// 🔥 更新折扣卡 applicableProductLimit 使用计数(跨商品全局)
|
|
1585
|
-
var bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
|
|
1586
|
-
if (['discount_card', 'product_discount_card'].includes(bundleDiscountTypeForCount)) {
|
|
1587
|
-
var currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
|
|
1588
|
-
usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
|
|
1518
|
+
if ((_selectedDiscount2.tag || _selectedDiscount2.type) === 'good_pass') {
|
|
1519
|
+
var _currentCount = usedProductIdCounts.get(_selectedDiscount2.product_id) || 0;
|
|
1520
|
+
usedProductIdCounts.set(_selectedDiscount2.product_id, _currentCount + 1);
|
|
1589
1521
|
}
|
|
1590
1522
|
|
|
1591
1523
|
// 🔥 生成唯一的 _id
|
|
1592
1524
|
var uniqueId = "".concat(flatItem._id, "_split_").concat(_i);
|
|
1593
1525
|
|
|
1594
1526
|
// 计算折扣后的价格(使用 getDiscountAmount,内部已处理 maxDeductionAmount)
|
|
1595
|
-
var discountedPrice = getDiscountAmount(
|
|
1527
|
+
var discountedPrice = getDiscountAmount(_selectedDiscount2, product.origin_total, product.origin_total);
|
|
1596
1528
|
var bundleDiscountAmount = new Decimal(product.origin_total || 0).minus(discountedPrice).toNumber();
|
|
1597
1529
|
debugger;
|
|
1598
|
-
|
|
1599
|
-
// 确定折扣类型
|
|
1600
|
-
var bundleDiscountType = currentBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : currentBundleDiscount.tag;
|
|
1601
1530
|
var _discountDetail = {
|
|
1602
1531
|
amount: bundleDiscountAmount,
|
|
1603
|
-
type:
|
|
1532
|
+
type: 'good_pass',
|
|
1604
1533
|
discount: {
|
|
1605
|
-
|
|
1606
|
-
discount_calculation_mode:
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
title: currentBundleDiscount.format_title,
|
|
1534
|
+
fixed_amount: product.origin_total,
|
|
1535
|
+
discount_calculation_mode: _selectedDiscount2 === null || _selectedDiscount2 === void 0 || (_selectedDiscount2$me = _selectedDiscount2.metadata) === null || _selectedDiscount2$me === void 0 ? void 0 : _selectedDiscount2$me.discount_calculation_mode,
|
|
1536
|
+
resource_id: _selectedDiscount2.id,
|
|
1537
|
+
title: _selectedDiscount2.format_title,
|
|
1610
1538
|
original_amount: product.origin_total,
|
|
1611
1539
|
product_id: product.id || product.product_id,
|
|
1612
|
-
discount_product_id:
|
|
1540
|
+
discount_product_id: _selectedDiscount2.product_id
|
|
1613
1541
|
},
|
|
1614
1542
|
metadata: {
|
|
1615
1543
|
// 🔥 使用拆分后的唯一 _id
|
|
1616
1544
|
custom_product_bundle_map_id: uniqueId,
|
|
1617
|
-
discount_rule_uncheck_flag:
|
|
1545
|
+
discount_rule_uncheck_flag: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.discount_rule_uncheck_flag,
|
|
1618
1546
|
num: 1
|
|
1619
1547
|
},
|
|
1620
1548
|
_num: 1,
|
|
1621
|
-
config:
|
|
1549
|
+
config: _selectedDiscount2 === null || _selectedDiscount2 === void 0 ? void 0 : _selectedDiscount2.config
|
|
1622
1550
|
};
|
|
1623
1551
|
|
|
1624
1552
|
// 记录实际应用的折扣
|
|
1625
|
-
var _appliedProducts = appliedDiscountProducts.get(
|
|
1553
|
+
var _appliedProducts = appliedDiscountProducts.get(_selectedDiscount2.id) || [];
|
|
1626
1554
|
_appliedProducts.push(_discountDetail);
|
|
1627
|
-
appliedDiscountProducts.set(
|
|
1555
|
+
appliedDiscountProducts.set(_selectedDiscount2.id, _appliedProducts);
|
|
1628
1556
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1629
1557
|
// 🔥 使用唯一的 _id
|
|
1630
1558
|
_id: uniqueId,
|
|
@@ -1635,263 +1563,36 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1635
1563
|
total: discountedPrice,
|
|
1636
1564
|
discount_list: [_discountDetail],
|
|
1637
1565
|
processed: true,
|
|
1638
|
-
_discountId:
|
|
1566
|
+
_discountId: _selectedDiscount2.id
|
|
1639
1567
|
}));
|
|
1640
1568
|
}
|
|
1641
1569
|
|
|
1642
|
-
//
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
if (['good_pass', 'discount_card', 'product_discount_card'].includes(nextDiscountType)) {
|
|
1653
|
-
var _nextDiscount$config;
|
|
1654
|
-
if (nextDiscount.config === undefined || !(nextDiscount !== null && nextDiscount !== void 0 && (_nextDiscount$config = nextDiscount.config) !== null && _nextDiscount$config !== void 0 && _nextDiscount$config.isAvailable)) {
|
|
1655
|
-
return false;
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
// 折扣卡时总价为0时不可用
|
|
1659
|
-
if ((Number(product.total) <= 0 || !product.total) && !((_product$discount_lis11 = product.discount_list) !== null && _product$discount_lis11 !== void 0 && _product$discount_lis11.find(function (n) {
|
|
1660
|
-
var _n$discount2;
|
|
1661
|
-
return ((_n$discount2 = n.discount) === null || _n$discount2 === void 0 ? void 0 : _n$discount2.resource_id) === nextDiscount.id;
|
|
1662
|
-
})) && nextDiscountType !== 'good_pass') return false;
|
|
1663
|
-
|
|
1664
|
-
// 商品券已被使用则跳过
|
|
1665
|
-
if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === 'good_pass') return false;
|
|
1666
|
-
|
|
1667
|
-
// 检查 maxUsagePerOrder 限制
|
|
1668
|
-
if (nextDiscountType === 'good_pass') {
|
|
1669
|
-
var _nextDiscount$config2;
|
|
1670
|
-
var maxUsagePerOrder = (_nextDiscount$config2 = nextDiscount.config) === null || _nextDiscount$config2 === void 0 ? void 0 : _nextDiscount$config2.maxUsagePerOrder;
|
|
1671
|
-
if (maxUsagePerOrder && maxUsagePerOrder > 0) {
|
|
1672
|
-
var currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
|
|
1673
|
-
if (currentUsedCount >= maxUsagePerOrder) {
|
|
1674
|
-
return false;
|
|
1675
|
-
}
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
// 检查折扣卡的 applicableProductLimit 限制
|
|
1680
|
-
if (['discount_card', 'product_discount_card'].includes(nextDiscountType)) {
|
|
1681
|
-
var _nextDiscount$config3;
|
|
1682
|
-
var limitConfig = ((_nextDiscount$config3 = nextDiscount.config) === null || _nextDiscount$config3 === void 0 ? void 0 : _nextDiscount$config3.applicableProductLimit) || 0;
|
|
1683
|
-
if (limitConfig > 0) {
|
|
1684
|
-
var currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
|
|
1685
|
-
if (currentUsedLimitCount >= limitConfig) {
|
|
1686
|
-
return false;
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
}
|
|
1690
|
-
var limitedData = nextDiscount.limited_relation_product_data;
|
|
1691
|
-
if (limitedData.type === 'product_all') {
|
|
1692
|
-
if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
|
|
1693
|
-
return false;
|
|
1694
|
-
}
|
|
1695
|
-
if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
|
|
1696
|
-
return false;
|
|
1697
|
-
}
|
|
1698
|
-
return true;
|
|
1699
|
-
} else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
|
|
1700
|
-
if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
|
|
1701
|
-
return false;
|
|
1702
|
-
}
|
|
1703
|
-
return true;
|
|
1704
|
-
}
|
|
1705
|
-
return false;
|
|
1706
|
-
});
|
|
1707
|
-
|
|
1708
|
-
// 没有更多可用折扣,剩余商品无折扣存储
|
|
1709
|
-
if (nextApplicableDiscounts.length === 0) {
|
|
1710
|
-
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1711
|
-
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1712
|
-
num: remainingNum,
|
|
1713
|
-
quantity: remainingNum,
|
|
1714
|
-
discount_list: [],
|
|
1715
|
-
processed: true
|
|
1716
|
-
}));
|
|
1717
|
-
break;
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
// 选择最优折扣
|
|
1721
|
-
var nextSelectedDiscountCard = nextApplicableDiscounts.find(function (n) {
|
|
1722
|
-
return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
|
|
1723
|
-
});
|
|
1724
|
-
var nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1725
|
-
|
|
1726
|
-
// 判断新折扣是否需要拆分
|
|
1727
|
-
var nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
|
|
1728
|
-
var nextIsGoodPass = nextDiscType === 'good_pass';
|
|
1729
|
-
var nextIsDiscountCard = ['discount_card', 'product_discount_card'].includes(nextDiscType);
|
|
1730
|
-
var nextApplicableProductLimit = ((_nextSelectedDiscount = nextSelectedDiscount.config) === null || _nextSelectedDiscount === void 0 ? void 0 : _nextSelectedDiscount.applicableProductLimit) || 0;
|
|
1731
|
-
var nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
|
|
1732
|
-
if (!nextIsNeedSplit) {
|
|
1733
|
-
var _nextBundleDiscount$m, _flatItem$parentProdu9;
|
|
1734
|
-
// 🔥 不需要拆分:直接应用折扣到所有剩余商品
|
|
1735
|
-
var nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1736
|
-
usedDiscounts.set(nextBundleDiscount.id, true);
|
|
1737
|
-
if ((nextBundleDiscount.tag || nextBundleDiscount.type) === 'good_pass') {
|
|
1738
|
-
var curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
|
|
1739
|
-
usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
|
|
1740
|
-
}
|
|
1741
|
-
var nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
|
|
1742
|
-
if (['discount_card', 'product_discount_card'].includes(nextNoSplitType)) {
|
|
1743
|
-
var _curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
|
|
1744
|
-
usedDiscountCardLimitCounts.set(nextBundleDiscount.id, _curCount + remainingNum);
|
|
1745
|
-
}
|
|
1746
|
-
var nextOriginTotal = product.original_price || product.price || 0;
|
|
1747
|
-
var nextTargetTotal = getDiscountAmount(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
|
|
1748
|
-
var nextDiscountAmount = new Decimal(nextOriginTotal).minus(nextTargetTotal).toNumber();
|
|
1749
|
-
var nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
|
|
1750
|
-
var nextBundleDiscType = nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : nextBundleDiscount.tag;
|
|
1751
|
-
var nextDiscountDetail = {
|
|
1752
|
-
amount: nextDiscountAmount * remainingNum,
|
|
1753
|
-
type: nextBundleDiscType,
|
|
1754
|
-
discount: {
|
|
1755
|
-
discount_card_type: nextBundleDiscount === null || nextBundleDiscount === void 0 || (_nextBundleDiscount$m = nextBundleDiscount.metadata) === null || _nextBundleDiscount$m === void 0 ? void 0 : _nextBundleDiscount$m.discount_card_type,
|
|
1756
|
-
fixed_amount: nextDiscountAmount,
|
|
1757
|
-
resource_id: nextBundleDiscount.id,
|
|
1758
|
-
title: nextBundleDiscount.format_title,
|
|
1759
|
-
original_amount: product.original_price,
|
|
1760
|
-
product_id: product.id,
|
|
1761
|
-
percent: nextBundleDiscount.par_value,
|
|
1762
|
-
discount_product_id: nextBundleDiscount.product_id
|
|
1763
|
-
},
|
|
1764
|
-
metadata: {
|
|
1765
|
-
custom_product_bundle_map_id: nextUniqueId,
|
|
1766
|
-
num: remainingNum
|
|
1767
|
-
},
|
|
1768
|
-
config: nextBundleDiscount === null || nextBundleDiscount === void 0 ? void 0 : nextBundleDiscount.config,
|
|
1769
|
-
_num: remainingNum * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
|
|
1770
|
-
};
|
|
1771
|
-
var nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
|
|
1772
|
-
nextAppliedProducts.push(nextDiscountDetail);
|
|
1773
|
-
appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
|
|
1774
|
-
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1775
|
-
_id: nextUniqueId,
|
|
1776
|
-
num: remainingNum,
|
|
1777
|
-
quantity: remainingNum,
|
|
1778
|
-
total: nextTargetTotal,
|
|
1779
|
-
price: new Decimal(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
|
|
1780
|
-
discount_list: [nextDiscountDetail],
|
|
1781
|
-
processed: true
|
|
1782
|
-
}));
|
|
1783
|
-
remainingNum = 0;
|
|
1784
|
-
break;
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
// 🔥 需要拆分:计算最大使用次数
|
|
1788
|
-
var nextMaxUsageLimit = void 0;
|
|
1789
|
-
if (nextIsGoodPass) {
|
|
1790
|
-
var _nextSelectedDiscount2;
|
|
1791
|
-
var nextGoodPassCount = nextApplicableDiscounts.filter(function (item) {
|
|
1792
|
-
return (item.tag || item.type) === 'good_pass';
|
|
1793
|
-
}).length;
|
|
1794
|
-
nextMaxUsageLimit = nextGoodPassCount;
|
|
1795
|
-
if ((_nextSelectedDiscount2 = nextSelectedDiscount.config) !== null && _nextSelectedDiscount2 !== void 0 && _nextSelectedDiscount2.maxUsagePerOrder) {
|
|
1796
|
-
var usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
|
|
1797
|
-
nextMaxUsageLimit = Math.min(nextGoodPassCount, Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount));
|
|
1798
|
-
}
|
|
1799
|
-
} else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
|
|
1800
|
-
var _usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
|
|
1801
|
-
nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - _usedLimitCount);
|
|
1802
|
-
} else {
|
|
1803
|
-
nextMaxUsageLimit = 1;
|
|
1804
|
-
}
|
|
1805
|
-
var nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
|
|
1806
|
-
if (nextSplitCount === 0) {
|
|
1807
|
-
// 已达使用上限,剩余商品无折扣存储
|
|
1808
|
-
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1809
|
-
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1810
|
-
num: remainingNum,
|
|
1811
|
-
quantity: remainingNum,
|
|
1812
|
-
discount_list: [],
|
|
1813
|
-
processed: true
|
|
1814
|
-
}));
|
|
1815
|
-
break;
|
|
1816
|
-
}
|
|
1817
|
-
|
|
1818
|
-
// 生成有折扣的商品
|
|
1819
|
-
for (var j = 0; j < nextSplitCount; j++) {
|
|
1820
|
-
var _nextBundleDiscount$m2;
|
|
1821
|
-
var _nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
|
|
1822
|
-
usedDiscounts.set(_nextBundleDiscount.id, true);
|
|
1823
|
-
if ((_nextBundleDiscount.tag || _nextBundleDiscount.type) === 'good_pass') {
|
|
1824
|
-
var _curCount2 = usedProductIdCounts.get(_nextBundleDiscount.product_id) || 0;
|
|
1825
|
-
usedProductIdCounts.set(_nextBundleDiscount.product_id, _curCount2 + 1);
|
|
1826
|
-
}
|
|
1827
|
-
var nextBundleDiscTypeForCount = _nextBundleDiscount.tag || _nextBundleDiscount.type;
|
|
1828
|
-
if (['discount_card', 'product_discount_card'].includes(nextBundleDiscTypeForCount)) {
|
|
1829
|
-
var curLimitCount = usedDiscountCardLimitCounts.get(_nextBundleDiscount.id) || 0;
|
|
1830
|
-
usedDiscountCardLimitCounts.set(_nextBundleDiscount.id, curLimitCount + 1);
|
|
1831
|
-
}
|
|
1832
|
-
var _nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
|
|
1833
|
-
var nextDiscountedPrice = getDiscountAmount(_nextBundleDiscount, product.origin_total, product.origin_total);
|
|
1834
|
-
var nextBundleDiscAmount = new Decimal(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
|
|
1835
|
-
var nextBundleDiscTypeStr = _nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _nextBundleDiscount.tag;
|
|
1836
|
-
var _nextDiscountDetail = {
|
|
1837
|
-
amount: nextBundleDiscAmount,
|
|
1838
|
-
type: nextBundleDiscTypeStr,
|
|
1839
|
-
discount: {
|
|
1840
|
-
discount_card_type: _nextBundleDiscount === null || _nextBundleDiscount === void 0 || (_nextBundleDiscount$m2 = _nextBundleDiscount.metadata) === null || _nextBundleDiscount$m2 === void 0 ? void 0 : _nextBundleDiscount$m2.discount_card_type,
|
|
1841
|
-
fixed_amount: nextBundleDiscAmount,
|
|
1842
|
-
resource_id: _nextBundleDiscount.id,
|
|
1843
|
-
title: _nextBundleDiscount.format_title,
|
|
1844
|
-
original_amount: product.origin_total,
|
|
1845
|
-
product_id: product.id,
|
|
1846
|
-
percent: _nextBundleDiscount.par_value,
|
|
1847
|
-
discount_product_id: _nextBundleDiscount.product_id
|
|
1848
|
-
},
|
|
1849
|
-
metadata: {
|
|
1850
|
-
custom_product_bundle_map_id: _nextUniqueId,
|
|
1851
|
-
num: 1
|
|
1852
|
-
},
|
|
1853
|
-
_num: 1,
|
|
1854
|
-
config: _nextBundleDiscount === null || _nextBundleDiscount === void 0 ? void 0 : _nextBundleDiscount.config
|
|
1855
|
-
};
|
|
1856
|
-
var _nextAppliedProducts = appliedDiscountProducts.get(_nextBundleDiscount.id) || [];
|
|
1857
|
-
_nextAppliedProducts.push(_nextDiscountDetail);
|
|
1858
|
-
appliedDiscountProducts.set(_nextBundleDiscount.id, _nextAppliedProducts);
|
|
1859
|
-
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1860
|
-
_id: _nextUniqueId,
|
|
1861
|
-
num: 1,
|
|
1862
|
-
quantity: 1,
|
|
1863
|
-
price: nextDiscountedPrice,
|
|
1864
|
-
total: nextDiscountedPrice,
|
|
1865
|
-
discount_list: [_nextDiscountDetail],
|
|
1866
|
-
processed: true,
|
|
1867
|
-
_discountId: _nextBundleDiscount.id
|
|
1868
|
-
}));
|
|
1869
|
-
continueSplitIndex++;
|
|
1870
|
-
}
|
|
1871
|
-
remainingNum -= nextSplitCount;
|
|
1570
|
+
// 生成无折扣的商品(剩余数量)
|
|
1571
|
+
if (normalNum > 0) {
|
|
1572
|
+
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1573
|
+
// 🔥 为剩余商品生成唯一的 _id
|
|
1574
|
+
_id: "".concat(flatItem._id, "_split_rest"),
|
|
1575
|
+
num: normalNum,
|
|
1576
|
+
quantity: normalNum,
|
|
1577
|
+
discount_list: _this3.filterDiscountListByType(flatItem.discount_list, 'promotion'),
|
|
1578
|
+
processed: true
|
|
1579
|
+
}));
|
|
1872
1580
|
}
|
|
1873
1581
|
} else {
|
|
1874
|
-
var
|
|
1875
|
-
//
|
|
1876
|
-
var
|
|
1877
|
-
usedDiscounts.set(
|
|
1878
|
-
// 🔥 更新 product_id
|
|
1879
|
-
if ((
|
|
1880
|
-
var _currentCount2 = usedProductIdCounts.get(
|
|
1881
|
-
usedProductIdCounts.set(
|
|
1882
|
-
}
|
|
1883
|
-
// 🔥 更新折扣卡 applicableProductLimit 使用计数(不拆分时按商品数量计数)
|
|
1884
|
-
var noSplitDiscountType = _currentBundleDiscount.tag || _currentBundleDiscount.type;
|
|
1885
|
-
if (['discount_card', 'product_discount_card'].includes(noSplitDiscountType)) {
|
|
1886
|
-
var bundleQuantity = product.num || 1;
|
|
1887
|
-
var currentNoSplitCount = usedDiscountCardLimitCounts.get(_currentBundleDiscount.id) || 0;
|
|
1888
|
-
usedDiscountCardLimitCounts.set(_currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
|
|
1582
|
+
var _selectedDiscount3$me, _selectedDiscount3$me2, _flatItem$parentProdu9;
|
|
1583
|
+
// 折扣卡:不拆分数量,直接应用
|
|
1584
|
+
var _selectedDiscount3 = selectedDiscountCard || applicableDiscounts[0];
|
|
1585
|
+
usedDiscounts.set(_selectedDiscount3.id, true);
|
|
1586
|
+
// 🔥 更新 product_id 使用计数(虽然此处主要是折扣卡,但保持一致性)
|
|
1587
|
+
if ((_selectedDiscount3.tag || _selectedDiscount3.type) === 'good_pass') {
|
|
1588
|
+
var _currentCount2 = usedProductIdCounts.get(_selectedDiscount3.product_id) || 0;
|
|
1589
|
+
usedProductIdCounts.set(_selectedDiscount3.product_id, _currentCount2 + 1);
|
|
1889
1590
|
}
|
|
1890
1591
|
var _productOriginTotal = product.original_price || product.price || 0;
|
|
1891
1592
|
|
|
1892
1593
|
// 🔥 检查是否是 order_level 固定金额折扣卡
|
|
1893
|
-
var _isOrderLevel = isOrderLevelFixedAmountDiscount(
|
|
1894
|
-
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(
|
|
1594
|
+
var _isOrderLevel = isOrderLevelFixedAmountDiscount(_selectedDiscount3);
|
|
1595
|
+
var _orderLevelAllocation = _isOrderLevel ? orderLevelDiscountAllocations.get(_selectedDiscount3.id) : null;
|
|
1895
1596
|
var _productAllocation = _orderLevelAllocation === null || _orderLevelAllocation === void 0 ? void 0 : _orderLevelAllocation.get(flatItem._id);
|
|
1896
1597
|
var targetProductTotal;
|
|
1897
1598
|
var fixedAmountPerItem;
|
|
@@ -1903,46 +1604,43 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
1903
1604
|
targetProductTotal = Math.max(new Decimal(_productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
|
|
1904
1605
|
} else {
|
|
1905
1606
|
// item_level 或其他类型:使用原有逻辑
|
|
1906
|
-
targetProductTotal = getDiscountAmount(
|
|
1607
|
+
targetProductTotal = getDiscountAmount(_selectedDiscount3, _productOriginTotal, _productOriginTotal);
|
|
1907
1608
|
fixedAmountPerItem = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1908
1609
|
}
|
|
1909
1610
|
|
|
1910
|
-
// 计算实际折扣金额
|
|
1911
|
-
var bundleActualDiscountAmount = new Decimal(_productOriginTotal).minus(targetProductTotal).toNumber();
|
|
1912
|
-
|
|
1913
1611
|
// 🔥 使用当前的 _id 作为唯一标识
|
|
1914
1612
|
var _uniqueId = flatItem._id;
|
|
1915
1613
|
debugger;
|
|
1916
1614
|
var _discountDetail2 = {
|
|
1917
|
-
amount:
|
|
1918
|
-
type:
|
|
1615
|
+
amount: fixedAmountPerItem * (product.num || 1),
|
|
1616
|
+
type: _selectedDiscount3.tag === 'product_discount_card' ? 'discount_card' : _selectedDiscount3.tag,
|
|
1919
1617
|
discount: {
|
|
1920
|
-
discount_card_type:
|
|
1921
|
-
fixed_amount:
|
|
1922
|
-
discount_calculation_mode:
|
|
1923
|
-
resource_id:
|
|
1924
|
-
title:
|
|
1618
|
+
discount_card_type: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me = _selectedDiscount3.metadata) === null || _selectedDiscount3$me === void 0 ? void 0 : _selectedDiscount3$me.discount_card_type,
|
|
1619
|
+
fixed_amount: fixedAmountPerItem,
|
|
1620
|
+
discount_calculation_mode: _selectedDiscount3 === null || _selectedDiscount3 === void 0 || (_selectedDiscount3$me2 = _selectedDiscount3.metadata) === null || _selectedDiscount3$me2 === void 0 ? void 0 : _selectedDiscount3$me2.discount_calculation_mode,
|
|
1621
|
+
resource_id: _selectedDiscount3.id,
|
|
1622
|
+
title: _selectedDiscount3.format_title,
|
|
1925
1623
|
original_amount: product.original_price,
|
|
1926
1624
|
product_id: product.id || product.product_id,
|
|
1927
|
-
percent:
|
|
1928
|
-
discount_product_id:
|
|
1625
|
+
percent: _selectedDiscount3.par_value,
|
|
1626
|
+
discount_product_id: _selectedDiscount3.product_id
|
|
1929
1627
|
},
|
|
1930
1628
|
metadata: _objectSpread({
|
|
1931
1629
|
// 🔥 使用唯一的 _id
|
|
1932
1630
|
custom_product_bundle_map_id: _uniqueId,
|
|
1933
|
-
discount_rule_uncheck_flag:
|
|
1631
|
+
discount_rule_uncheck_flag: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.discount_rule_uncheck_flag,
|
|
1934
1632
|
num: product.num || 1
|
|
1935
1633
|
}, _productDiscountDifference !== undefined && {
|
|
1936
1634
|
product_discount_difference: _productDiscountDifference
|
|
1937
1635
|
}),
|
|
1938
|
-
config:
|
|
1939
|
-
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$
|
|
1636
|
+
config: _selectedDiscount3 === null || _selectedDiscount3 === void 0 ? void 0 : _selectedDiscount3.config,
|
|
1637
|
+
_num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
|
|
1940
1638
|
};
|
|
1941
1639
|
|
|
1942
1640
|
// 记录实际应用的折扣
|
|
1943
|
-
var _appliedProducts2 = appliedDiscountProducts.get(
|
|
1641
|
+
var _appliedProducts2 = appliedDiscountProducts.get(_selectedDiscount3.id) || [];
|
|
1944
1642
|
_appliedProducts2.push(_discountDetail2);
|
|
1945
|
-
appliedDiscountProducts.set(
|
|
1643
|
+
appliedDiscountProducts.set(_selectedDiscount3.id, _appliedProducts2);
|
|
1946
1644
|
processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
|
|
1947
1645
|
total: targetProductTotal,
|
|
1948
1646
|
price: new Decimal(_productOriginTotal || 0).minus(fixedAmountPerItem).toNumber(),
|
|
@@ -2070,7 +1768,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2070
1768
|
product_id: bundleItem.product_id,
|
|
2071
1769
|
price: item.price,
|
|
2072
1770
|
num: item.num,
|
|
2073
|
-
quantity: item.num,
|
|
2074
1771
|
discount_list: updatedDiscountList
|
|
2075
1772
|
}));
|
|
2076
1773
|
});
|
|
@@ -2094,7 +1791,6 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2094
1791
|
product_id: bundleItem.product_id,
|
|
2095
1792
|
price: item.price,
|
|
2096
1793
|
num: item.num,
|
|
2097
|
-
quantity: item.num,
|
|
2098
1794
|
discount_list: _updatedDiscountList
|
|
2099
1795
|
}));
|
|
2100
1796
|
} else {
|
|
@@ -2109,8 +1805,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2109
1805
|
|
|
2110
1806
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=1)
|
|
2111
1807
|
var updatedMainDiscountList = mainProductData.discount_list.map(function (discount) {
|
|
2112
|
-
var _discount$
|
|
2113
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
1808
|
+
var _discount$metadata6, _discount$metadata7;
|
|
1809
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata6 = discount.metadata) !== null && _discount$metadata6 !== void 0 && _discount$metadata6.custom_product_bundle_map_id) {
|
|
2114
1810
|
// bundle的discount_list保持不变
|
|
2115
1811
|
return discount;
|
|
2116
1812
|
}
|
|
@@ -2118,7 +1814,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2118
1814
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2119
1815
|
// num: 1,
|
|
2120
1816
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2121
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1817
|
+
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata7 = discount.metadata) === null || _discount$metadata7 === void 0 ? void 0 : _discount$metadata7.custom_product_bundle_map_id,
|
|
2122
1818
|
num: 1
|
|
2123
1819
|
})
|
|
2124
1820
|
});
|
|
@@ -2183,8 +1879,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2183
1879
|
|
|
2184
1880
|
// 🔥 更新主商品自己的 discount_list 中的 num(quantity=原quantity-1)
|
|
2185
1881
|
var updatedMainDiscountListOriginal = mainProductData.discount_list.map(function (discount) {
|
|
2186
|
-
var _discount$
|
|
2187
|
-
if (discount !== null && discount !== void 0 && (_discount$
|
|
1882
|
+
var _discount$metadata8, _discount$metadata9;
|
|
1883
|
+
if (discount !== null && discount !== void 0 && (_discount$metadata8 = discount.metadata) !== null && _discount$metadata8 !== void 0 && _discount$metadata8.custom_product_bundle_map_id) {
|
|
2188
1884
|
// bundle的discount_list保持不变
|
|
2189
1885
|
return discount;
|
|
2190
1886
|
}
|
|
@@ -2192,7 +1888,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2192
1888
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2193
1889
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2194
1890
|
num: mainProductQuantity - 1,
|
|
2195
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1891
|
+
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata9 = discount.metadata) === null || _discount$metadata9 === void 0 ? void 0 : _discount$metadata9.custom_product_bundle_map_id
|
|
2196
1892
|
})
|
|
2197
1893
|
// num: mainProductQuantity - 1,
|
|
2198
1894
|
});
|
|
@@ -2262,11 +1958,11 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2262
1958
|
var nextBundleSellingPrice = (_ref14 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref14 !== void 0 ? _ref14 : bundleItem.bundle_selling_price;
|
|
2263
1959
|
// 🔥 更新 discount_list 中的 num,使其与拆分后的 item.num 一致
|
|
2264
1960
|
var updatedDiscountList = (item.discount_list || []).map(function (discount) {
|
|
2265
|
-
var _discount$
|
|
1961
|
+
var _discount$metadata10;
|
|
2266
1962
|
return _objectSpread(_objectSpread({}, discount), {}, {
|
|
2267
1963
|
metadata: _objectSpread(_objectSpread({}, discount.metadata), {}, {
|
|
2268
1964
|
num: item.num,
|
|
2269
|
-
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$
|
|
1965
|
+
custom_product_bundle_map_id: discount === null || discount === void 0 || (_discount$metadata10 = discount.metadata) === null || _discount$metadata10 === void 0 ? void 0 : _discount$metadata10.custom_product_bundle_map_id
|
|
2270
1966
|
})
|
|
2271
1967
|
// num: item.num, // 使用拆分后的 num
|
|
2272
1968
|
});
|
|
@@ -2301,18 +1997,18 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2301
1997
|
newTotal = (_mainProductData$tota = mainProductData.total) !== null && _mainProductData$tota !== void 0 ? _mainProductData$tota : newTotal;
|
|
2302
1998
|
newOriginTotal = (_mainProductData$orig3 = mainProductData.origin_total) !== null && _mainProductData$orig3 !== void 0 ? _mainProductData$orig3 : newOriginTotal;
|
|
2303
1999
|
} else {
|
|
2304
|
-
// 累加bundle的折后价格(只累加一次)
|
|
2000
|
+
// 累加 bundle 的折后价格(只累加一次)
|
|
2305
2001
|
if (newBundle.length > 0) {
|
|
2306
2002
|
newBundle.forEach(function (item) {
|
|
2307
|
-
var _item$
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
newOriginTotal += Number(originalPrice) * Number(item.num);
|
|
2003
|
+
var _item$bundle_selling_2;
|
|
2004
|
+
var bundleSellingPrice = (_item$bundle_selling_2 = item.bundle_selling_price) !== null && _item$bundle_selling_2 !== void 0 ? _item$bundle_selling_2 : item.price;
|
|
2005
|
+
newTotal += Number(bundleSellingPrice) * Number(item.num);
|
|
2311
2006
|
});
|
|
2007
|
+
|
|
2312
2008
|
// 计算原始总价(不考虑折扣)
|
|
2313
2009
|
newBundle.forEach(function (item) {
|
|
2314
|
-
var _item$
|
|
2315
|
-
var originalPrice = ((_item$
|
|
2010
|
+
var _item$discount_list3;
|
|
2011
|
+
var originalPrice = ((_item$discount_list3 = item.discount_list) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3[0]) === null || _item$discount_list3 === void 0 || (_item$discount_list3 = _item$discount_list3.discount) === null || _item$discount_list3 === void 0 ? void 0 : _item$discount_list3.original_amount) || item.price;
|
|
2316
2012
|
newOriginTotal += Number(originalPrice) * Number(item.num);
|
|
2317
2013
|
});
|
|
2318
2014
|
}
|
|
@@ -2458,12 +2154,12 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2458
2154
|
return true; // 单独购买时可用
|
|
2459
2155
|
}
|
|
2460
2156
|
if (isBundleItem) {
|
|
2461
|
-
var _flatItem$bundleItem10, _flatItem$bundleItem11, _flatItem$originProdu, _flatItem$
|
|
2157
|
+
var _flatItem$bundleItem10, _flatItem$bundleItem11, _flatItem$originProdu, _flatItem$parentProdu10;
|
|
2462
2158
|
// 套餐中购买时,判断是否为原价
|
|
2463
2159
|
var priceType = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type;
|
|
2464
2160
|
var priceTypeExt = (_flatItem$bundleItem11 = flatItem.bundleItem) === null || _flatItem$bundleItem11 === void 0 ? void 0 : _flatItem$bundleItem11.price_type_ext;
|
|
2465
2161
|
// 主商品id
|
|
2466
|
-
var mainProductId = (flatItem === null || flatItem === void 0 || (_flatItem$originProdu = flatItem.originProduct) === null || _flatItem$originProdu === void 0 || (_flatItem$originProdu = _flatItem$originProdu._productOrigin) === null || _flatItem$originProdu === void 0 ? void 0 : _flatItem$originProdu.id) || (flatItem === null || flatItem === void 0 || (_flatItem$
|
|
2162
|
+
var mainProductId = (flatItem === null || flatItem === void 0 || (_flatItem$originProdu = flatItem.originProduct) === null || _flatItem$originProdu === void 0 || (_flatItem$originProdu = _flatItem$originProdu._productOrigin) === null || _flatItem$originProdu === void 0 ? void 0 : _flatItem$originProdu.id) || (flatItem === null || flatItem === void 0 || (_flatItem$parentProdu10 = flatItem.parentProduct) === null || _flatItem$parentProdu10 === void 0 ? void 0 : _flatItem$parentProdu10.id) || 0;
|
|
2467
2163
|
// original_price 对应:
|
|
2468
2164
|
// 1. price_type: "markup" && price_type_ext: "product_price"
|
|
2469
2165
|
// markup_price 对应:
|
|
@@ -2657,8 +2353,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2657
2353
|
_context3.next = 3;
|
|
2658
2354
|
return this.core.effects.emit("".concat(this.name, ":onDestroy"), {});
|
|
2659
2355
|
case 3:
|
|
2356
|
+
console.log('[Rules] 已销毁');
|
|
2660
2357
|
_get(_getPrototypeOf(RulesModule.prototype), "destroy", this).call(this);
|
|
2661
|
-
case
|
|
2358
|
+
case 5:
|
|
2662
2359
|
case "end":
|
|
2663
2360
|
return _context3.stop();
|
|
2664
2361
|
}
|
|
@@ -2676,6 +2373,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
|
|
|
2676
2373
|
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
2677
2374
|
while (1) switch (_context4.prev = _context4.next) {
|
|
2678
2375
|
case 0:
|
|
2376
|
+
console.log('[Rules] clear');
|
|
2377
|
+
case 1:
|
|
2679
2378
|
case "end":
|
|
2680
2379
|
return _context4.stop();
|
|
2681
2380
|
}
|