@pisell/pisellos 0.0.567 → 0.0.569
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 +6 -9
- package/dist/model/strategy/adapter/promotion/evaluator.js +3 -2
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/adapter/walletPass/utils.js +7 -7
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/BaseModule.d.ts +2 -2
- package/dist/modules/BaseModule.js +4 -4
- package/dist/modules/BookingContext/index.d.ts +48 -0
- package/dist/modules/BookingContext/index.js +566 -0
- package/dist/modules/BookingContext/types.d.ts +102 -0
- package/dist/modules/BookingContext/types.js +51 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +302 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +149 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +249 -0
- package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/dist/modules/BookingContext/utils/flexible.js +56 -0
- package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
- package/dist/modules/BookingContext/utils/index.d.ts +11 -0
- package/dist/modules/BookingContext/utils/index.js +11 -0
- package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/dist/modules/BookingContext/utils/noResource.js +77 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/dist/modules/BookingContext/utils/orderLineDisplay.js +36 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/dist/modules/BookingContext/utils/productExtend.js +339 -0
- package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
- package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
- package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
- package/dist/modules/BookingContext/utils/resources.js +486 -0
- package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
- package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +26 -6
- package/dist/modules/Cart/utils/changePrice.js +27 -20
- package/dist/modules/Customer/index.d.ts +20 -0
- package/dist/modules/Customer/index.js +172 -83
- package/dist/modules/Customer/types.d.ts +2 -0
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.d.ts +2 -1
- package/dist/modules/Discount/index.js +37 -12
- package/dist/modules/Discount/types.d.ts +1 -0
- package/dist/modules/OpenData/index.d.ts +8 -0
- package/dist/modules/OpenData/index.js +35 -17
- package/dist/modules/Order/index.d.ts +449 -24
- package/dist/modules/Order/index.js +5437 -608
- package/dist/modules/Order/types.d.ts +693 -88
- package/dist/modules/Order/types.js +68 -1
- package/dist/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/dist/modules/Order/utils/bundleDiscountHydration.js +144 -0
- package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
- package/dist/modules/Order/utils.d.ts +167 -18
- package/dist/modules/Order/utils.js +960 -165
- package/dist/modules/Payment/index.d.ts +10 -9
- package/dist/modules/Payment/index.js +508 -874
- package/dist/modules/Payment/types.d.ts +40 -16
- package/dist/modules/Payment/utils.d.ts +1 -1
- package/dist/modules/Payment/utils.js +4 -3
- package/dist/modules/Payment/walletpass.js +48 -34
- package/dist/modules/Product/types.d.ts +29 -7
- package/dist/modules/ProductList/index.d.ts +17 -13
- package/dist/modules/ProductList/index.js +184 -74
- package/dist/modules/ProductList/types.d.ts +17 -0
- package/dist/modules/Quotation/index.d.ts +22 -2
- package/dist/modules/Quotation/index.js +108 -42
- package/dist/modules/Quotation/types.d.ts +19 -0
- package/dist/modules/ResourcePlanner/index.d.ts +24 -0
- package/dist/modules/ResourcePlanner/index.js +181 -0
- package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
- package/dist/modules/ResourcePlanner/planner.js +1069 -0
- package/dist/modules/ResourcePlanner/types.d.ts +227 -0
- package/dist/modules/ResourcePlanner/types.js +1 -0
- package/dist/modules/Rules/index.d.ts +8 -10
- package/dist/modules/Rules/index.js +219 -114
- package/dist/modules/Rules/types.d.ts +14 -3
- package/dist/modules/SalesSummary/index.d.ts +23 -26
- package/dist/modules/SalesSummary/index.js +152 -46
- package/dist/modules/SalesSummary/types.d.ts +9 -1
- package/dist/modules/SalesSummary/utils.d.ts +3 -22
- package/dist/modules/SalesSummary/utils.js +803 -163
- package/dist/modules/Schedule/getDateIsInSchedule.js +14 -7
- package/dist/modules/Schedule/index.d.ts +18 -5
- package/dist/modules/Schedule/index.js +78 -24
- package/dist/modules/Schedule/types.d.ts +2 -0
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/modules/Summary/index.js +4 -3
- package/dist/modules/SurchargeList/index.d.ts +18 -0
- package/dist/modules/SurchargeList/index.js +185 -0
- package/dist/modules/SurchargeList/types.d.ts +15 -0
- package/dist/modules/SurchargeList/types.js +1 -0
- package/dist/modules/index.d.ts +3 -0
- package/dist/modules/index.js +4 -1
- package/dist/plugins/app.d.ts +2 -0
- package/dist/plugins/request.d.ts +1 -0
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.d.ts +462 -8
- package/dist/server/index.js +6137 -714
- package/dist/server/modules/floor-plan/index.d.ts +39 -0
- package/dist/server/modules/floor-plan/index.js +595 -0
- package/dist/server/modules/floor-plan/types.d.ts +43 -0
- package/dist/server/modules/floor-plan/types.js +13 -0
- package/dist/server/modules/index.d.ts +7 -2
- package/dist/server/modules/index.js +6 -0
- package/dist/server/modules/menu/index.js +32 -41
- package/dist/server/modules/order/index.d.ts +207 -14
- package/dist/server/modules/order/index.js +2326 -379
- package/dist/server/modules/order/types.d.ts +76 -5
- package/dist/server/modules/order/types.js +14 -1
- package/dist/server/modules/order/utils/filterBookings.d.ts +7 -1
- package/dist/server/modules/order/utils/filterBookings.js +118 -11
- package/dist/server/modules/order/utils/filterOrders.js +242 -14
- package/dist/server/modules/payment/index.d.ts +28 -0
- package/dist/server/modules/payment/index.js +305 -0
- package/dist/server/modules/payment/types.d.ts +9 -0
- package/dist/server/modules/payment/types.js +1 -0
- package/dist/server/modules/products/index.d.ts +105 -14
- package/dist/server/modules/products/index.js +1397 -540
- package/dist/server/modules/products/types.d.ts +34 -1
- package/dist/server/modules/products/types.js +4 -0
- package/dist/server/modules/quotation/index.d.ts +39 -0
- package/dist/server/modules/quotation/index.js +289 -86
- package/dist/server/modules/resource/index.d.ts +2 -3
- package/dist/server/modules/resource/index.js +105 -84
- package/dist/server/modules/schedule/index.d.ts +6 -4
- package/dist/server/modules/schedule/index.js +137 -114
- package/dist/server/test.json +713 -0
- package/dist/server/types.d.ts +2 -0
- package/dist/server/utils/product.js +2 -3
- package/dist/server/utils/small-ticket.d.ts +71 -0
- package/dist/server/utils/small-ticket.js +963 -0
- package/dist/solution/BaseSales/index.d.ts +378 -0
- package/dist/solution/BaseSales/index.js +4006 -0
- package/dist/solution/BaseSales/types.d.ts +394 -0
- package/dist/solution/BaseSales/types.js +40 -0
- package/dist/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/dist/solution/BaseSales/utils/cartPromotion.js +1450 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
- package/dist/solution/BaseSales/utils/parseSalesResponse.js +157 -0
- package/dist/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
- package/dist/solution/BaseSales/utils/quotationPrice.js +250 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +218 -0
- package/dist/solution/BaseSales/utils.d.ts +40 -0
- package/dist/solution/BaseSales/utils.js +263 -0
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.d.ts +393 -24
- package/dist/solution/BookingTicket/index.js +2506 -445
- package/dist/solution/BookingTicket/types.d.ts +191 -6
- package/dist/solution/BookingTicket/types.js +83 -10
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
- package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
- package/dist/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
- package/dist/solution/BookingTicket/utils/addTimeAvailability.js +95 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
- package/dist/solution/BookingTicket/utils/bookingStatus.js +136 -0
- package/dist/solution/BookingTicket/utils/cartView.d.ts +29 -0
- package/dist/solution/BookingTicket/utils/cartView.js +209 -0
- package/dist/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/dist/solution/BookingTicket/utils/exampleData.js +183 -0
- package/dist/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
- package/dist/solution/BookingTicket/utils/orderCustomer.js +31 -0
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
- package/dist/solution/BookingTicket/utils/resolveBestAddTimePlan.js +438 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +400 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +41 -1
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +56 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +36 -34
- package/dist/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/dist/solution/BookingTicket/utils/scan/index.js +26 -18
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/dist/solution/BookingTicket/utils/scan/scanProductValues.js +150 -0
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
- package/dist/solution/BookingTicket/utils/sessionCatalogStale.js +78 -0
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.d.ts +1 -0
- package/dist/solution/Checkout/index.js +199 -277
- package/dist/solution/Checkout/utils/index.js +8 -20
- package/dist/solution/RegisterAndLogin/config.js +2 -10
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/Sales/index.d.ts +50 -5
- package/dist/solution/Sales/index.js +484 -92
- package/dist/solution/Sales/types.d.ts +26 -2
- package/dist/solution/ScanOrder/index.d.ts +27 -21
- package/dist/solution/ScanOrder/index.js +509 -454
- package/dist/solution/ScanOrder/types.d.ts +33 -11
- package/dist/solution/ScanOrder/types.js +4 -5
- package/dist/solution/ScanOrder/utils.d.ts +4 -1
- package/dist/solution/ScanOrder/utils.js +109 -34
- package/dist/solution/ShopDiscount/index.js +6 -11
- package/dist/solution/UnifiedBookingSales/index.d.ts +183 -0
- package/dist/solution/UnifiedBookingSales/index.js +1871 -0
- package/dist/solution/UnifiedBookingSales/types.d.ts +143 -0
- package/dist/solution/UnifiedBookingSales/types.js +11 -0
- package/dist/solution/VenueBooking/index.d.ts +34 -20
- package/dist/solution/VenueBooking/index.js +630 -505
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +9 -3
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/dist/types/index.d.ts +11 -1
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.js +130 -131
- package/lib/effects/index.js +46 -57
- package/lib/index.js +92 -53
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +84 -63
- package/lib/model/strategy/adapter/promotion/evaluator.js +383 -232
- package/lib/model/strategy/adapter/promotion/examples.js +139 -159
- package/lib/model/strategy/adapter/promotion/index.js +1 -49
- package/lib/model/strategy/adapter/promotion/type.js +199 -35
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -152
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +654 -402
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.d.ts +2 -2
- package/lib/modules/BaseModule.js +26 -49
- package/lib/modules/BookingContext/index.d.ts +48 -0
- package/lib/modules/BookingContext/index.js +390 -0
- package/lib/modules/BookingContext/types.d.ts +102 -0
- package/lib/modules/BookingContext/types.js +48 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +286 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +148 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +76 -0
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +242 -0
- package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
- package/lib/modules/BookingContext/utils/flexible.js +63 -0
- package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
- package/lib/modules/BookingContext/utils/formatResourceList.js +35 -0
- package/lib/modules/BookingContext/utils/index.d.ts +11 -0
- package/lib/modules/BookingContext/utils/index.js +126 -0
- package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
- package/lib/modules/BookingContext/utils/noResource.js +78 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.d.ts +1 -0
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +29 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
- package/lib/modules/BookingContext/utils/productExtend.js +330 -0
- package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
- package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
- package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
- package/lib/modules/BookingContext/utils/resourceSelection.js +24 -0
- package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
- package/lib/modules/BookingContext/utils/resources.js +419 -0
- package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
- package/lib/modules/BookingContext/utils/serviceTimes.js +161 -0
- package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
- package/lib/modules/BookingContext/utils/timeSlices.js +114 -0
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +331 -244
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +72 -78
- package/lib/modules/Cart/utils/changePrice.js +37 -67
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.d.ts +20 -0
- package/lib/modules/Customer/index.js +270 -154
- package/lib/modules/Customer/types.d.ts +2 -0
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.d.ts +2 -1
- package/lib/modules/Discount/index.js +133 -113
- package/lib/modules/Discount/types.d.ts +1 -0
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.d.ts +8 -0
- package/lib/modules/OpenData/index.js +81 -74
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.d.ts +449 -24
- package/lib/modules/Order/index.js +3834 -489
- package/lib/modules/Order/types.d.ts +693 -88
- package/lib/modules/Order/types.js +78 -33
- package/lib/modules/Order/utils/bundleDiscountHydration.d.ts +5 -0
- package/lib/modules/Order/utils/bundleDiscountHydration.js +106 -0
- package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
- package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
- package/lib/modules/Order/utils/orderCollectionIdentity.js +353 -0
- package/lib/modules/Order/utils.d.ts +167 -18
- package/lib/modules/Order/utils.js +1247 -345
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.d.ts +10 -9
- package/lib/modules/Payment/index.js +542 -502
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.d.ts +40 -16
- package/lib/modules/Payment/types.js +216 -107
- package/lib/modules/Payment/utils.d.ts +1 -1
- package/lib/modules/Payment/utils.js +53 -49
- package/lib/modules/Payment/walletpass.js +231 -203
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.d.ts +29 -7
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.d.ts +17 -13
- package/lib/modules/ProductList/index.js +160 -118
- package/lib/modules/ProductList/types.d.ts +17 -0
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.d.ts +22 -2
- package/lib/modules/Quotation/index.js +123 -89
- package/lib/modules/Quotation/types.d.ts +19 -0
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/ResourcePlanner/index.d.ts +24 -0
- package/lib/modules/ResourcePlanner/index.js +147 -0
- package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
- package/lib/modules/ResourcePlanner/planner.js +895 -0
- package/lib/modules/ResourcePlanner/types.d.ts +227 -0
- package/lib/modules/ResourcePlanner/types.js +5 -0
- package/lib/modules/Rules/index.d.ts +8 -10
- package/lib/modules/Rules/index.js +1286 -894
- package/lib/modules/Rules/types.d.ts +14 -3
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.d.ts +23 -26
- package/lib/modules/SalesSummary/index.js +130 -71
- package/lib/modules/SalesSummary/types.d.ts +9 -1
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.d.ts +3 -22
- package/lib/modules/SalesSummary/utils.js +738 -250
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +345 -171
- package/lib/modules/Schedule/index.d.ts +18 -5
- package/lib/modules/Schedule/index.js +139 -114
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.d.ts +2 -0
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -70
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +782 -429
- package/lib/modules/SurchargeList/index.d.ts +18 -0
- package/lib/modules/SurchargeList/index.js +95 -0
- package/lib/modules/SurchargeList/types.d.ts +15 -0
- package/lib/modules/SurchargeList/types.js +5 -0
- package/lib/modules/index.d.ts +3 -0
- package/lib/modules/index.js +245 -57
- package/lib/plugins/app.d.ts +2 -0
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.d.ts +1 -0
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.d.ts +462 -8
- package/lib/server/index.js +4668 -713
- package/lib/server/modules/floor-plan/index.d.ts +39 -0
- package/lib/server/modules/floor-plan/index.js +306 -0
- package/lib/server/modules/floor-plan/types.d.ts +43 -0
- package/lib/server/modules/floor-plan/types.js +19 -0
- package/lib/server/modules/index.d.ts +7 -2
- package/lib/server/modules/index.js +106 -59
- package/lib/server/modules/menu/index.js +146 -122
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.d.ts +207 -14
- package/lib/server/modules/order/index.js +1463 -316
- package/lib/server/modules/order/types.d.ts +76 -5
- package/lib/server/modules/order/types.js +117 -32
- package/lib/server/modules/order/utils/filterBookings.d.ts +7 -1
- package/lib/server/modules/order/utils/filterBookings.js +288 -146
- package/lib/server/modules/order/utils/filterOrders.js +318 -64
- package/lib/server/modules/payment/index.d.ts +28 -0
- package/lib/server/modules/payment/index.js +168 -0
- package/lib/server/modules/payment/types.d.ts +9 -0
- package/lib/server/modules/payment/types.js +5 -0
- package/lib/server/modules/products/index.d.ts +105 -14
- package/lib/server/modules/products/index.js +969 -383
- package/lib/server/modules/products/types.d.ts +34 -1
- package/lib/server/modules/products/types.js +44 -34
- package/lib/server/modules/quotation/index.d.ts +39 -0
- package/lib/server/modules/quotation/index.js +220 -77
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.d.ts +2 -3
- package/lib/server/modules/resource/index.js +269 -214
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.d.ts +6 -4
- package/lib/server/modules/schedule/index.js +158 -132
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/test.json +713 -0
- package/lib/server/types.d.ts +2 -0
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +197 -140
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/small-ticket.d.ts +71 -0
- package/lib/server/utils/small-ticket.js +926 -0
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BaseSales/index.d.ts +378 -0
- package/lib/solution/BaseSales/index.js +2367 -0
- package/lib/solution/BaseSales/types.d.ts +394 -0
- package/lib/solution/BaseSales/types.js +47 -0
- package/lib/solution/BaseSales/utils/cartPromotion.d.ts +287 -0
- package/lib/solution/BaseSales/utils/cartPromotion.js +1155 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +144 -0
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +140 -0
- package/lib/solution/BaseSales/utils/quotationPrice.d.ts +18 -0
- package/lib/solution/BaseSales/utils/quotationPrice.js +231 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +63 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +215 -0
- package/lib/solution/BaseSales/utils.d.ts +40 -0
- package/lib/solution/BaseSales/utils.js +259 -0
- package/lib/solution/BookingByStep/index.js +1530 -1343
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.d.ts +393 -24
- package/lib/solution/BookingTicket/index.js +1459 -160
- package/lib/solution/BookingTicket/types.d.ts +191 -6
- package/lib/solution/BookingTicket/types.js +101 -66
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +117 -0
- package/lib/solution/BookingTicket/utils/addProductDecision.js +353 -0
- package/lib/solution/BookingTicket/utils/addTimeAvailability.d.ts +35 -0
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +94 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.d.ts +77 -0
- package/lib/solution/BookingTicket/utils/bookingStatus.js +136 -0
- package/lib/solution/BookingTicket/utils/cartView.d.ts +29 -0
- package/lib/solution/BookingTicket/utils/cartView.js +200 -0
- package/lib/solution/BookingTicket/utils/exampleData.d.ts +123 -0
- package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.d.ts +4 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.js +35 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.d.ts +185 -0
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +387 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +36 -0
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +220 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.d.ts +4 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +85 -80
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +32 -0
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +64 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -80
- package/lib/solution/BookingTicket/utils/scan/index.d.ts +5 -0
- package/lib/solution/BookingTicket/utils/scan/index.js +103 -95
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.d.ts +21 -0
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +115 -0
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.d.ts +23 -0
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +83 -0
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.d.ts +1 -0
- package/lib/solution/Checkout/index.js +1461 -1169
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +228 -159
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +495 -470
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.d.ts +50 -5
- package/lib/solution/Sales/index.js +495 -220
- package/lib/solution/Sales/types.d.ts +26 -2
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.d.ts +27 -21
- package/lib/solution/ScanOrder/index.js +908 -904
- package/lib/solution/ScanOrder/types.d.ts +33 -11
- package/lib/solution/ScanOrder/types.js +33 -34
- package/lib/solution/ScanOrder/utils.d.ts +4 -1
- package/lib/solution/ScanOrder/utils.js +457 -344
- package/lib/solution/ShopDiscount/index.js +230 -236
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +309 -172
- package/lib/solution/UnifiedBookingSales/index.d.ts +183 -0
- package/lib/solution/UnifiedBookingSales/index.js +1050 -0
- package/lib/solution/UnifiedBookingSales/types.d.ts +143 -0
- package/lib/solution/UnifiedBookingSales/types.js +14 -0
- package/lib/solution/VenueBooking/index.d.ts +34 -20
- package/lib/solution/VenueBooking/index.js +982 -950
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
- package/lib/solution/VenueBooking/types.js +20 -40
- package/lib/solution/VenueBooking/utils/dateSummary.js +22 -54
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +6 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +96 -108
- package/lib/solution/VenueBooking/utils/smartPricing.js +112 -100
- package/lib/solution/VenueBooking/utils/timeSlot.js +133 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +124 -37
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.d.ts +11 -1
- package/lib/types/index.js +4 -16
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
- package/dist/solution/Checkout/appointmentDemo.json +0 -1
- package/lib/solution/Checkout/appointmentDemo.json +0 -1
|
@@ -0,0 +1,1450 @@
|
|
|
1
|
+
var _excluded = ["_promotionTags"];
|
|
2
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
5
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
6
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
7
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
8
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
9
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
13
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
15
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
16
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
17
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
18
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
19
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
20
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
21
|
+
import Decimal from 'decimal.js';
|
|
22
|
+
import { cloneDeep } from 'lodash-es';
|
|
23
|
+
import { composeLinePrice, createUuidV4, getProductSkuOptions, sumOptionUnitPrice } from "../../../modules/Order/utils";
|
|
24
|
+
import { buildProductLineFingerprint, getSafeProductNum } from "../../ScanOrder/utils";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Cart promotion 工具集(OS 内部纯函数)
|
|
28
|
+
*
|
|
29
|
+
* 这是 `private-materials/components/booking/hooks/usePromotion.ts` 中促销/赠品
|
|
30
|
+
* 核心计算(evaluator → 拆分 / 计价 → 赠品差异化 / 未满足提示 / 标签)的 OS 等价实现。
|
|
31
|
+
*
|
|
32
|
+
* 与 legacy 的关键差异:
|
|
33
|
+
* - legacy 操作 booking `_extend.*` 形状;OS 操作 `OrderProduct.metadata.*` 形状。
|
|
34
|
+
* - 行唯一标识不再用 `_id`,统一改用 `metadata.unique_identification_number`。
|
|
35
|
+
* - 赠品标签存到 `metadata._giftInfo`;主商品促销信息存到 `metadata._promotion`;
|
|
36
|
+
* 商品卡列表的促销 tag 存到 `metadata._promotionTags`。
|
|
37
|
+
*
|
|
38
|
+
* 仅暴露纯函数,不持有任何状态;评估器以参数注入。
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* const evaluator = appHelper.utils.promotionEvaluator;
|
|
42
|
+
* const result = processCartPromotion(tempOrder.products, evaluator);
|
|
43
|
+
* // result.products: 处理后的商品(带 _promotion / 拆分)
|
|
44
|
+
* // result.giftActions: 需要 add / reduce / remove 的赠品操作
|
|
45
|
+
* // result.unfulfilledPromotions: 未满足策略列表(购物车底部 alert)
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
// ============================================
|
|
49
|
+
// 类型定义
|
|
50
|
+
// ============================================
|
|
51
|
+
|
|
52
|
+
/** Cart 评估器协议(只描述本文件用到的方法,避免循环依赖) */
|
|
53
|
+
|
|
54
|
+
/** 单个赠品减量项 */
|
|
55
|
+
|
|
56
|
+
/** 赠品新增项 */
|
|
57
|
+
|
|
58
|
+
/** 赠品操作集合(OS 侧根据它落地 tempOrder.products) */
|
|
59
|
+
|
|
60
|
+
/** 未满足促销提示项(购物车底部 alert 数据源) */
|
|
61
|
+
|
|
62
|
+
/** 商品卡促销标签结构(写入 `metadata._promotionTags`) */
|
|
63
|
+
|
|
64
|
+
/** processCartPromotion 输出 */
|
|
65
|
+
|
|
66
|
+
// ============================================
|
|
67
|
+
// 字段适配 helper
|
|
68
|
+
// ============================================
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 获取商品的「主商品基础价」用于评估器入参。
|
|
72
|
+
*
|
|
73
|
+
* 优先级(与 OS v2 schema 一致):
|
|
74
|
+
* 1. `metadata.source_product_price`
|
|
75
|
+
* 2. `metadata.main_product_original_price` 减去 option 合计
|
|
76
|
+
* 3. `original_price`
|
|
77
|
+
*/
|
|
78
|
+
export function getOrderProductBasePrice(product) {
|
|
79
|
+
var _ref, _product$original_pri;
|
|
80
|
+
var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
|
|
81
|
+
var optionSum = sumOptionUnitPrice(getProductSkuOptions(product)).toNumber();
|
|
82
|
+
if (metadata.source_product_price !== undefined) {
|
|
83
|
+
var _v = Number(metadata.source_product_price);
|
|
84
|
+
return Number.isFinite(_v) ? _v : 0;
|
|
85
|
+
}
|
|
86
|
+
if (metadata.main_product_original_price !== undefined) {
|
|
87
|
+
var _v2 = Number(metadata.main_product_original_price) - optionSum;
|
|
88
|
+
return Number.isFinite(_v2) ? _v2 : 0;
|
|
89
|
+
}
|
|
90
|
+
var v = Number((_ref = (_product$original_pri = product === null || product === void 0 ? void 0 : product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : product === null || product === void 0 ? void 0 : product.selling_price) !== null && _ref !== void 0 ? _ref : 0);
|
|
91
|
+
return Number.isFinite(v) ? v : 0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 促销均摊专用原价(对齐 legacy `getMainOriginalPrice` 语义)。
|
|
96
|
+
*
|
|
97
|
+
* 必须用券前原价做 X_ITEMS_FOR_Y_PRICE 比例拆分;`source_product_price` 在上一轮 applyPromotion
|
|
98
|
+
* 后可能已被写成促销价(如 5 / 9 / 1),若继续用它会导致同商品两行出现 9+1 而非 5+5。
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* getOrderProductOriginalPriceForPromotion({ metadata: { source_product_price: '9', main_product_original_price: '5.80' } });
|
|
102
|
+
* // => 5.8
|
|
103
|
+
*/
|
|
104
|
+
export function getOrderProductOriginalPriceForPromotion(product) {
|
|
105
|
+
var _metadata$_promotion;
|
|
106
|
+
var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
|
|
107
|
+
var optionSum = sumOptionUnitPrice(getProductSkuOptions(product)).toNumber();
|
|
108
|
+
if (metadata.main_product_original_price !== undefined && metadata.main_product_original_price !== null && metadata.main_product_original_price !== '') {
|
|
109
|
+
var v = Number(metadata.main_product_original_price) - optionSum;
|
|
110
|
+
if (Number.isFinite(v) && v >= 0) return v;
|
|
111
|
+
}
|
|
112
|
+
var promoOriginal = (_metadata$_promotion = metadata._promotion) === null || _metadata$_promotion === void 0 ? void 0 : _metadata$_promotion.originalPrice;
|
|
113
|
+
if (promoOriginal !== undefined && promoOriginal !== null && promoOriginal !== '') {
|
|
114
|
+
var _v3 = Number(promoOriginal);
|
|
115
|
+
if (Number.isFinite(_v3) && _v3 >= 0) return _v3;
|
|
116
|
+
}
|
|
117
|
+
return getOrderProductBasePrice(product);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 写入/清除促销 discount_list(type=promotion)。
|
|
122
|
+
*
|
|
123
|
+
* applyDiscount → applyProductDiscountPrices 会从 source_product_price 减去 discount_list 合计
|
|
124
|
+
* 重算 main_product_selling_price;保留券前 source 时必须同步写入促销差额,否则会还原成原价。
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* updatePromotionDiscountList(line, { title: '2 items for $10', amount: '17.00', original_amount: '22.00', fixed_amount: '17.00' });
|
|
128
|
+
*/
|
|
129
|
+
function updatePromotionDiscountList(item, promotionDiscount) {
|
|
130
|
+
var discountList = Array.isArray(item.discount_list) ? _toConsumableArray(item.discount_list) : [];
|
|
131
|
+
discountList = discountList.filter(function (d) {
|
|
132
|
+
return (d === null || d === void 0 ? void 0 : d.type) !== 'promotion';
|
|
133
|
+
});
|
|
134
|
+
if (promotionDiscount) {
|
|
135
|
+
discountList.push({
|
|
136
|
+
type: 'promotion',
|
|
137
|
+
amount: promotionDiscount.amount,
|
|
138
|
+
discount: {
|
|
139
|
+
original_amount: promotionDiscount.original_amount,
|
|
140
|
+
fixed_amount: promotionDiscount.fixed_amount,
|
|
141
|
+
title: promotionDiscount.title,
|
|
142
|
+
resource_id: ''
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (discountList.length > 0) {
|
|
147
|
+
item.discount_list = discountList;
|
|
148
|
+
} else {
|
|
149
|
+
delete item.discount_list;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
var X_ITEMS_FOR_Y_PRICE = 'X_ITEMS_FOR_Y_PRICE';
|
|
153
|
+
var BUY_X_GET_Y_FREE = 'BUY_X_GET_Y_FREE';
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 将促销单价写入 OrderProduct(含 metadata 三字段 + promotion discount_list)。
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* applyPromoUnitPriceToLine(newItem, { promoUnitPrice: '5.00', originalBasePrice: 1, strategyTitle: '2 for 10' });
|
|
160
|
+
*/
|
|
161
|
+
function applyPromoUnitPriceToLine(item, input) {
|
|
162
|
+
var metadata = item.metadata || (item.metadata = {});
|
|
163
|
+
var optionSum = sumOptionUnitPrice(getProductSkuOptions(item)).toNumber();
|
|
164
|
+
var promoUnitPrice = new Decimal(Number(input.promoUnitPrice) || 0).toDecimalPlaces(2).toFixed(2);
|
|
165
|
+
var mainSelling = new Decimal(Number(promoUnitPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
166
|
+
var catalogSource = new Decimal(input.originalBasePrice).toDecimalPlaces(2).toFixed(2);
|
|
167
|
+
metadata.source_product_price = catalogSource;
|
|
168
|
+
metadata.main_product_original_price = new Decimal(Number(catalogSource) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
169
|
+
metadata.main_product_selling_price = mainSelling;
|
|
170
|
+
metadata.price_schema_version = 2;
|
|
171
|
+
item.selling_price = composeLinePrice({
|
|
172
|
+
mainPrice: mainSelling,
|
|
173
|
+
bundle: item.product_bundle
|
|
174
|
+
});
|
|
175
|
+
item.original_price = composeLinePrice({
|
|
176
|
+
mainPrice: metadata.main_product_original_price,
|
|
177
|
+
bundle: item.product_bundle,
|
|
178
|
+
useOriginalBundle: true
|
|
179
|
+
});
|
|
180
|
+
var discountAmount = new Decimal(input.originalBasePrice).minus(Number(promoUnitPrice) || 0).toDecimalPlaces(2).toFixed(2);
|
|
181
|
+
if (Number(catalogSource) !== Number(promoUnitPrice)) {
|
|
182
|
+
updatePromotionDiscountList(item, {
|
|
183
|
+
title: input.strategyTitle || '',
|
|
184
|
+
amount: discountAmount,
|
|
185
|
+
original_amount: catalogSource,
|
|
186
|
+
fixed_amount: discountAmount
|
|
187
|
+
});
|
|
188
|
+
} else {
|
|
189
|
+
updatePromotionDiscountList(item, null);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function getPromotionActionType(promotion) {
|
|
193
|
+
var _promotion$strategyMe, _actions$;
|
|
194
|
+
if (promotion !== null && promotion !== void 0 && promotion.actionType) return String(promotion.actionType);
|
|
195
|
+
var actions = promotion === null || promotion === void 0 || (_promotion$strategyMe = promotion.strategyMetadata) === null || _promotion$strategyMe === void 0 ? void 0 : _promotion$strategyMe.actions;
|
|
196
|
+
if (Array.isArray(actions) && (_actions$ = actions[0]) !== null && _actions$ !== void 0 && _actions$.type) return String(actions[0].type);
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* 同款行凑满 X件Y元 且仅该行参与时,按 Y/X 计算期望单价(2 件 $10 → $5)。
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* resolveXItemsExpectedUnitPrice({ actionType: 'X_ITEMS_FOR_Y_PRICE', actionDetail: { x: 2, price: 10 } }, 2);
|
|
205
|
+
*/
|
|
206
|
+
function resolveXItemsExpectedUnitPrice(promotion, sourceCartNum) {
|
|
207
|
+
if (getPromotionActionType(promotion) !== X_ITEMS_FOR_Y_PRICE) return undefined;
|
|
208
|
+
var detail = promotion === null || promotion === void 0 ? void 0 : promotion.actionDetail;
|
|
209
|
+
var x = Number(detail === null || detail === void 0 ? void 0 : detail.x);
|
|
210
|
+
var y = Number(detail === null || detail === void 0 ? void 0 : detail.price);
|
|
211
|
+
if (!Number.isFinite(x) || x <= 0 || !Number.isFinite(y)) return undefined;
|
|
212
|
+
if (sourceCartNum < x) return undefined;
|
|
213
|
+
return Number(new Decimal(y).div(x).toDecimalPlaces(2).toFixed(2));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* 合并「同商品 + 同规格指纹 + 同促销策略 + 同促销单价」的参与促销行(num 累加)。
|
|
218
|
+
* 避免 Browse Items 连续加购同款时拆成多行且单价被错误均摊。
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* mergeIdenticalPromotionCartLines(processedProducts);
|
|
222
|
+
*/
|
|
223
|
+
export function mergeIdenticalPromotionCartLines(products) {
|
|
224
|
+
if (!Array.isArray(products) || products.length <= 1) {
|
|
225
|
+
return _toConsumableArray(products || []);
|
|
226
|
+
}
|
|
227
|
+
var merged = [];
|
|
228
|
+
var indexByKey = new Map();
|
|
229
|
+
var _iterator = _createForOfIteratorHelper(products),
|
|
230
|
+
_step;
|
|
231
|
+
try {
|
|
232
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
233
|
+
var _line$metadata, _ref2, _line$metadata$source, _line$metadata2, _ref3, _promotion$finalPrice, _line$metadata3, _line$booking_uid, _line$metadata4, _line$order_detail_id, _line$product_variant;
|
|
234
|
+
var line = _step.value;
|
|
235
|
+
if (getGiftInfo(line)) {
|
|
236
|
+
merged.push(line);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
var promotion = line === null || line === void 0 || (_line$metadata = line.metadata) === null || _line$metadata === void 0 ? void 0 : _line$metadata._promotion;
|
|
240
|
+
if (!(promotion !== null && promotion !== void 0 && promotion.inPromotion) || !promotion.strategyId) {
|
|
241
|
+
merged.push(line);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
var fingerprint = buildProductLineFingerprint(getProductSkuOptions(line), line.product_bundle);
|
|
245
|
+
var unitPrice = String((_ref2 = (_line$metadata$source = (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2.source_product_price) !== null && _line$metadata$source !== void 0 ? _line$metadata$source : line.selling_price) !== null && _ref2 !== void 0 ? _ref2 : '');
|
|
246
|
+
var promoUnitPrice = String((_ref3 = (_promotion$finalPrice = promotion.finalPrice) !== null && _promotion$finalPrice !== void 0 ? _promotion$finalPrice : (_line$metadata3 = line.metadata) === null || _line$metadata3 === void 0 ? void 0 : _line$metadata3.main_product_selling_price) !== null && _ref3 !== void 0 ? _ref3 : '');
|
|
247
|
+
var noteSignature = getProductLineNoteSignature(line);
|
|
248
|
+
var lineMergeBoundary = getPromotionLineMergeBoundary(line);
|
|
249
|
+
var bookingUid = (_line$booking_uid = line === null || line === void 0 ? void 0 : line.booking_uid) !== null && _line$booking_uid !== void 0 ? _line$booking_uid : line === null || line === void 0 || (_line$metadata4 = line.metadata) === null || _line$metadata4 === void 0 ? void 0 : _line$metadata4.booking_uid;
|
|
250
|
+
var orderDetailId = (_line$order_detail_id = line === null || line === void 0 ? void 0 : line.order_detail_id) !== null && _line$order_detail_id !== void 0 ? _line$order_detail_id : line === null || line === void 0 ? void 0 : line.orderDetailId;
|
|
251
|
+
var mergeKey = [line.product_id, (_line$product_variant = line.product_variant_id) !== null && _line$product_variant !== void 0 ? _line$product_variant : 0, fingerprint, noteSignature, lineMergeBoundary, bookingUid ? String(bookingUid) : '', orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '' ? String(orderDetailId) : '', promotion.strategyId, unitPrice, promoUnitPrice].join('#');
|
|
252
|
+
var hitIndex = indexByKey.get(mergeKey);
|
|
253
|
+
if (hitIndex === undefined) {
|
|
254
|
+
indexByKey.set(mergeKey, merged.length);
|
|
255
|
+
merged.push(line);
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
var target = merged[hitIndex];
|
|
259
|
+
target.num = getSafeProductNum(Number(target.num || 0) + Number(line.num || 0));
|
|
260
|
+
}
|
|
261
|
+
} catch (err) {
|
|
262
|
+
_iterator.e(err);
|
|
263
|
+
} finally {
|
|
264
|
+
_iterator.f();
|
|
265
|
+
}
|
|
266
|
+
return merged;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* 同一原购物车行被多个「inPromotion」评估结果命中时(如买赠不改价 + X件Y元),
|
|
271
|
+
* 优先保留 X件Y元 定价,并恢复加购前的行数量。
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* dedupePromotionProcessedLines(processedProducts);
|
|
275
|
+
*/
|
|
276
|
+
function dedupePromotionProcessedLines(lines) {
|
|
277
|
+
if (!Array.isArray(lines) || lines.length <= 1) return _toConsumableArray(lines || []);
|
|
278
|
+
var passthrough = [];
|
|
279
|
+
var buckets = new Map();
|
|
280
|
+
var _iterator2 = _createForOfIteratorHelper(lines),
|
|
281
|
+
_step2;
|
|
282
|
+
try {
|
|
283
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
284
|
+
var _line$metadata6;
|
|
285
|
+
var line = _step2.value;
|
|
286
|
+
var promo = line === null || line === void 0 || (_line$metadata6 = line.metadata) === null || _line$metadata6 === void 0 ? void 0 : _line$metadata6._promotion;
|
|
287
|
+
var originalUid = String(line._originalProductUid || getOrderProductUid(line) || '');
|
|
288
|
+
if (!(promo !== null && promo !== void 0 && promo.inPromotion) || !originalUid) {
|
|
289
|
+
passthrough.push(line);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
var group = buckets.get(originalUid) || [];
|
|
293
|
+
group.push(line);
|
|
294
|
+
buckets.set(originalUid, group);
|
|
295
|
+
}
|
|
296
|
+
} catch (err) {
|
|
297
|
+
_iterator2.e(err);
|
|
298
|
+
} finally {
|
|
299
|
+
_iterator2.f();
|
|
300
|
+
}
|
|
301
|
+
var promotionDelta = function promotionDelta(line) {
|
|
302
|
+
var _line$metadata5;
|
|
303
|
+
var promo = (_line$metadata5 = line.metadata) === null || _line$metadata5 === void 0 ? void 0 : _line$metadata5._promotion;
|
|
304
|
+
var original = Number(promo === null || promo === void 0 ? void 0 : promo.originalPrice);
|
|
305
|
+
var final = Number(promo === null || promo === void 0 ? void 0 : promo.finalPrice);
|
|
306
|
+
if (!Number.isFinite(original) || !Number.isFinite(final)) return 0;
|
|
307
|
+
return Math.abs(original - final);
|
|
308
|
+
};
|
|
309
|
+
var deduped = [].concat(passthrough);
|
|
310
|
+
var _iterator3 = _createForOfIteratorHelper(buckets),
|
|
311
|
+
_step3;
|
|
312
|
+
try {
|
|
313
|
+
var _loop = function _loop() {
|
|
314
|
+
var _winner$metadata, _winner$metadata2, _winner$metadata3;
|
|
315
|
+
var _step3$value = _slicedToArray(_step3.value, 2),
|
|
316
|
+
originalUid = _step3$value[0],
|
|
317
|
+
group = _step3$value[1];
|
|
318
|
+
if (group.length === 1) {
|
|
319
|
+
deduped.push(group[0]);
|
|
320
|
+
return 1; // continue
|
|
321
|
+
}
|
|
322
|
+
var sourceCartNum = Math.max.apply(Math, _toConsumableArray(group.map(function (line) {
|
|
323
|
+
return Number(line._sourceCartNum || line.num || 0);
|
|
324
|
+
})));
|
|
325
|
+
var pricingLines = group.filter(function (line) {
|
|
326
|
+
return promotionDelta(line) > 0;
|
|
327
|
+
});
|
|
328
|
+
var xItemsLines = (pricingLines.length ? pricingLines : group).filter(function (line) {
|
|
329
|
+
var _line$metadata7;
|
|
330
|
+
return getPromotionActionType((_line$metadata7 = line.metadata) === null || _line$metadata7 === void 0 ? void 0 : _line$metadata7._promotion) === X_ITEMS_FOR_Y_PRICE;
|
|
331
|
+
});
|
|
332
|
+
var pool = xItemsLines.length ? xItemsLines : pricingLines.length ? pricingLines : group;
|
|
333
|
+
var winner = pool[0];
|
|
334
|
+
var expectedUnit = resolveXItemsExpectedUnitPrice((_winner$metadata = winner.metadata) === null || _winner$metadata === void 0 ? void 0 : _winner$metadata._promotion, sourceCartNum);
|
|
335
|
+
if (expectedUnit != null && pool.length > 1) {
|
|
336
|
+
winner = pool.reduce(function (best, line) {
|
|
337
|
+
var _best$metadata, _line$metadata8;
|
|
338
|
+
var bestDiff = Math.abs(Number((_best$metadata = best.metadata) === null || _best$metadata === void 0 || (_best$metadata = _best$metadata._promotion) === null || _best$metadata === void 0 ? void 0 : _best$metadata.finalPrice) - expectedUnit);
|
|
339
|
+
var lineDiff = Math.abs(Number((_line$metadata8 = line.metadata) === null || _line$metadata8 === void 0 || (_line$metadata8 = _line$metadata8._promotion) === null || _line$metadata8 === void 0 ? void 0 : _line$metadata8.finalPrice) - expectedUnit);
|
|
340
|
+
return lineDiff < bestDiff ? line : best;
|
|
341
|
+
}, pool[0]);
|
|
342
|
+
} else if (pool.length > 1 && !expectedUnit) {
|
|
343
|
+
winner = pool.reduce(function (best, line) {
|
|
344
|
+
var _best$metadata2, _line$metadata9, _line$metadata10;
|
|
345
|
+
var bestFinal = Number((_best$metadata2 = best.metadata) === null || _best$metadata2 === void 0 || (_best$metadata2 = _best$metadata2._promotion) === null || _best$metadata2 === void 0 ? void 0 : _best$metadata2.finalPrice);
|
|
346
|
+
var lineFinal = Number((_line$metadata9 = line.metadata) === null || _line$metadata9 === void 0 || (_line$metadata9 = _line$metadata9._promotion) === null || _line$metadata9 === void 0 ? void 0 : _line$metadata9.finalPrice);
|
|
347
|
+
var original = Number((_line$metadata10 = line.metadata) === null || _line$metadata10 === void 0 || (_line$metadata10 = _line$metadata10._promotion) === null || _line$metadata10 === void 0 ? void 0 : _line$metadata10.originalPrice);
|
|
348
|
+
if (Number.isFinite(original) && lineFinal >= original && bestFinal >= original) {
|
|
349
|
+
return lineFinal < bestFinal ? line : best;
|
|
350
|
+
}
|
|
351
|
+
return promotionDelta(line) > promotionDelta(best) ? line : best;
|
|
352
|
+
}, pool[0]);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// X件Y元:评估器会按单件均摊产出多条 inPromotion 行(如 $1 + $9),
|
|
356
|
+
// dedupe 应合并为「同组 X件Y元 行 num 之和」,不能用 sourceCartNum(整单 3 件)。
|
|
357
|
+
var winnerIsXItems = getPromotionActionType((_winner$metadata2 = winner.metadata) === null || _winner$metadata2 === void 0 ? void 0 : _winner$metadata2._promotion) === X_ITEMS_FOR_Y_PRICE;
|
|
358
|
+
if (winnerIsXItems) {
|
|
359
|
+
var xItemsGroupLines = group.filter(function (line) {
|
|
360
|
+
var _line$metadata11;
|
|
361
|
+
return getPromotionActionType((_line$metadata11 = line.metadata) === null || _line$metadata11 === void 0 ? void 0 : _line$metadata11._promotion) === X_ITEMS_FOR_Y_PRICE;
|
|
362
|
+
});
|
|
363
|
+
var evaluatedPromoQty = xItemsGroupLines.reduce(function (sum, line) {
|
|
364
|
+
return sum + Number(line.num || 0);
|
|
365
|
+
}, 0);
|
|
366
|
+
winner.num = getSafeProductNum(evaluatedPromoQty || winner.num || 1);
|
|
367
|
+
} else {
|
|
368
|
+
winner.num = getSafeProductNum(sourceCartNum || winner.num || 1);
|
|
369
|
+
}
|
|
370
|
+
var recomputeUnit = resolveXItemsExpectedUnitPrice((_winner$metadata3 = winner.metadata) === null || _winner$metadata3 === void 0 ? void 0 : _winner$metadata3._promotion, sourceCartNum);
|
|
371
|
+
if (recomputeUnit != null) {
|
|
372
|
+
var _promo$strategyMetada;
|
|
373
|
+
var _promo = winner.metadata._promotion;
|
|
374
|
+
applyPromoUnitPriceToLine(winner, {
|
|
375
|
+
promoUnitPrice: recomputeUnit,
|
|
376
|
+
originalBasePrice: Number(_promo.originalPrice),
|
|
377
|
+
strategyTitle: (_promo$strategyMetada = _promo.strategyMetadata) === null || _promo$strategyMetada === void 0 ? void 0 : _promo$strategyMetada.name
|
|
378
|
+
});
|
|
379
|
+
_promo.finalPrice = recomputeUnit;
|
|
380
|
+
}
|
|
381
|
+
var _iterator4 = _createForOfIteratorHelper(group),
|
|
382
|
+
_step4;
|
|
383
|
+
try {
|
|
384
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
385
|
+
var _line$metadata12, _winner$metadata4;
|
|
386
|
+
var _line = _step4.value;
|
|
387
|
+
var giftInfo = (_line$metadata12 = _line.metadata) === null || _line$metadata12 === void 0 || (_line$metadata12 = _line$metadata12._promotion) === null || _line$metadata12 === void 0 ? void 0 : _line$metadata12.giftInfo;
|
|
388
|
+
if (giftInfo && (_winner$metadata4 = winner.metadata) !== null && _winner$metadata4 !== void 0 && _winner$metadata4._promotion && !winner.metadata._promotion.giftInfo) {
|
|
389
|
+
winner.metadata._promotion.giftInfo = giftInfo;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
} catch (err) {
|
|
393
|
+
_iterator4.e(err);
|
|
394
|
+
} finally {
|
|
395
|
+
_iterator4.f();
|
|
396
|
+
}
|
|
397
|
+
deduped.push(winner);
|
|
398
|
+
};
|
|
399
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
400
|
+
if (_loop()) continue;
|
|
401
|
+
}
|
|
402
|
+
} catch (err) {
|
|
403
|
+
_iterator3.e(err);
|
|
404
|
+
} finally {
|
|
405
|
+
_iterator3.f();
|
|
406
|
+
}
|
|
407
|
+
return deduped;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/** 获取行 uid(统一以 `metadata.unique_identification_number` 为唯一键) */
|
|
411
|
+
export function getOrderProductUid(product) {
|
|
412
|
+
var _ref4, _product$metadata$uni, _product$metadata;
|
|
413
|
+
return String((_ref4 = (_product$metadata$uni = product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product === null || product === void 0 ? void 0 : product.unique_identification_number) !== null && _ref4 !== void 0 ? _ref4 : '');
|
|
414
|
+
}
|
|
415
|
+
function getGiftInfo(product) {
|
|
416
|
+
var _product$metadata2;
|
|
417
|
+
return (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2._giftInfo) || (product === null || product === void 0 ? void 0 : product._giftInfo) || null;
|
|
418
|
+
}
|
|
419
|
+
function getProductLineNoteSignature(product) {
|
|
420
|
+
var note = product === null || product === void 0 ? void 0 : product.note;
|
|
421
|
+
if (typeof note !== 'string') return '';
|
|
422
|
+
var normalizedNote = note.trim();
|
|
423
|
+
if (!normalizedNote) return '';
|
|
424
|
+
var uid = getOrderProductUid(product);
|
|
425
|
+
return uid ? "note:".concat(uid) : "note:".concat(normalizedNote);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 编辑订单时,历史行仍参与整车促销评估,但不能与本次新增行合并。
|
|
430
|
+
* 以历史行 uid 作为促销前后的行边界;新增行返回空边界,仍保留原有合并语义。
|
|
431
|
+
*/
|
|
432
|
+
function getPromotionLineMergeBoundary(product) {
|
|
433
|
+
var _product$metadata3;
|
|
434
|
+
if ((product === null || product === void 0 || (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.is_edit_for_runtime) !== true) return '';
|
|
435
|
+
return "edit:".concat(getOrderProductUid(product));
|
|
436
|
+
}
|
|
437
|
+
function isPersistedGeneratedVoucher(product) {
|
|
438
|
+
var _product$order_detail;
|
|
439
|
+
var orderDetailId = (_product$order_detail = product === null || product === void 0 ? void 0 : product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : product === null || product === void 0 ? void 0 : product.orderDetailId;
|
|
440
|
+
if (orderDetailId === undefined || orderDetailId === null || orderDetailId === '') {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
|
|
444
|
+
return (product === null || product === void 0 ? void 0 : product.extension_type) === 'product_voucher' || metadata.parent_order_detail_id !== undefined || metadata.gift_card_type !== undefined;
|
|
445
|
+
}
|
|
446
|
+
function getProductBundleForEvaluator(product) {
|
|
447
|
+
var bundles = Array.isArray(product === null || product === void 0 ? void 0 : product.product_bundle) ? product.product_bundle : [];
|
|
448
|
+
return bundles.map(function (b) {
|
|
449
|
+
var _ref5, _b$bundle_product_id, _ref6, _b$bundle_variant_id, _ref7, _b$num, _ref8, _b$bundle_selling_pri, _ref9, _ref10, _b$original_price, _ref11, _b$bundle_id, _ref12, _b$_bundle_product_id;
|
|
450
|
+
return {
|
|
451
|
+
product_id: (_ref5 = (_b$bundle_product_id = b === null || b === void 0 ? void 0 : b.bundle_product_id) !== null && _b$bundle_product_id !== void 0 ? _b$bundle_product_id : b === null || b === void 0 ? void 0 : b._bundle_product_id) !== null && _ref5 !== void 0 ? _ref5 : b === null || b === void 0 ? void 0 : b.product_id,
|
|
452
|
+
product_variant_id: (_ref6 = (_b$bundle_variant_id = b === null || b === void 0 ? void 0 : b.bundle_variant_id) !== null && _b$bundle_variant_id !== void 0 ? _b$bundle_variant_id : b === null || b === void 0 ? void 0 : b.product_variant_id) !== null && _ref6 !== void 0 ? _ref6 : 0,
|
|
453
|
+
quantity: Number((_ref7 = (_b$num = b === null || b === void 0 ? void 0 : b.num) !== null && _b$num !== void 0 ? _b$num : b === null || b === void 0 ? void 0 : b.quantity) !== null && _ref7 !== void 0 ? _ref7 : 1) || 1,
|
|
454
|
+
price: Number((_ref8 = (_b$bundle_selling_pri = b === null || b === void 0 ? void 0 : b.bundle_selling_price) !== null && _b$bundle_selling_pri !== void 0 ? _b$bundle_selling_pri : b === null || b === void 0 ? void 0 : b.price) !== null && _ref8 !== void 0 ? _ref8 : 0) || 0,
|
|
455
|
+
original_price: Number((_ref9 = (_ref10 = (_b$original_price = b === null || b === void 0 ? void 0 : b.original_price) !== null && _b$original_price !== void 0 ? _b$original_price : b === null || b === void 0 ? void 0 : b.product_price) !== null && _ref10 !== void 0 ? _ref10 : b === null || b === void 0 ? void 0 : b.price) !== null && _ref9 !== void 0 ? _ref9 : 0) || 0,
|
|
456
|
+
id: (_ref11 = (_b$bundle_id = b === null || b === void 0 ? void 0 : b.bundle_id) !== null && _b$bundle_id !== void 0 ? _b$bundle_id : b === null || b === void 0 ? void 0 : b.id) !== null && _ref11 !== void 0 ? _ref11 : 0,
|
|
457
|
+
_bundle_product_id: (_ref12 = (_b$_bundle_product_id = b === null || b === void 0 ? void 0 : b._bundle_product_id) !== null && _b$_bundle_product_id !== void 0 ? _b$_bundle_product_id : b === null || b === void 0 ? void 0 : b.bundle_product_id) !== null && _ref12 !== void 0 ? _ref12 : b === null || b === void 0 ? void 0 : b.product_id
|
|
458
|
+
};
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* 促销评估前合并同 SKU 拆分行(含促销/原价行),避免加购后仅前 2 件享受优惠。
|
|
464
|
+
* 带 `booking_uid` 的预约行不参与合并(每次加车独立 booking + 商品行)。
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* consolidateMainProductsForPromotion([
|
|
468
|
+
* { item: promoLineNum2, originalListIndex: 0 },
|
|
469
|
+
* { item: regularLineNum2, originalListIndex: 1 },
|
|
470
|
+
* ]);
|
|
471
|
+
* // => 单行 num=4,清除 _promotion 后重新评估
|
|
472
|
+
*/
|
|
473
|
+
export function buildConsolidateKeyForPromotion(item) {
|
|
474
|
+
var _item$booking_uid, _item$metadata, _item$order_detail_id, _item$product_variant3;
|
|
475
|
+
var fingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
|
|
476
|
+
var noteSignature = getProductLineNoteSignature(item);
|
|
477
|
+
var lineMergeBoundary = getPromotionLineMergeBoundary(item);
|
|
478
|
+
var bookingUid = (_item$booking_uid = item === null || item === void 0 ? void 0 : item.booking_uid) !== null && _item$booking_uid !== void 0 ? _item$booking_uid : item === null || item === void 0 || (_item$metadata = item.metadata) === null || _item$metadata === void 0 ? void 0 : _item$metadata.booking_uid;
|
|
479
|
+
var orderDetailId = (_item$order_detail_id = item === null || item === void 0 ? void 0 : item.order_detail_id) !== null && _item$order_detail_id !== void 0 ? _item$order_detail_id : item === null || item === void 0 ? void 0 : item.orderDetailId;
|
|
480
|
+
if (orderDetailId !== undefined && orderDetailId !== null && orderDetailId !== '') {
|
|
481
|
+
var _item$product_variant;
|
|
482
|
+
return [item.product_id, (_item$product_variant = item.product_variant_id) !== null && _item$product_variant !== void 0 ? _item$product_variant : 0, fingerprint, noteSignature, lineMergeBoundary, String(orderDetailId)].join('#');
|
|
483
|
+
}
|
|
484
|
+
if (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '') {
|
|
485
|
+
var _item$product_variant2;
|
|
486
|
+
return [item.product_id, (_item$product_variant2 = item.product_variant_id) !== null && _item$product_variant2 !== void 0 ? _item$product_variant2 : 0, fingerprint, noteSignature, lineMergeBoundary, String(bookingUid)].join('#');
|
|
487
|
+
}
|
|
488
|
+
return [item.product_id, (_item$product_variant3 = item.product_variant_id) !== null && _item$product_variant3 !== void 0 ? _item$product_variant3 : 0, fingerprint, noteSignature, lineMergeBoundary].join('#');
|
|
489
|
+
}
|
|
490
|
+
function consolidateMainProductsForPromotion(entries) {
|
|
491
|
+
if (!Array.isArray(entries) || entries.length <= 1) {
|
|
492
|
+
return _toConsumableArray(entries || []);
|
|
493
|
+
}
|
|
494
|
+
var groups = new Map();
|
|
495
|
+
var _iterator5 = _createForOfIteratorHelper(entries),
|
|
496
|
+
_step5;
|
|
497
|
+
try {
|
|
498
|
+
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
|
499
|
+
var _item$metadata2;
|
|
500
|
+
var _step5$value = _step5.value,
|
|
501
|
+
item = _step5$value.item,
|
|
502
|
+
originalListIndex = _step5$value.originalListIndex;
|
|
503
|
+
var key = buildConsolidateKeyForPromotion(item);
|
|
504
|
+
var wasInPromotion = (item === null || item === void 0 || (_item$metadata2 = item.metadata) === null || _item$metadata2 === void 0 || (_item$metadata2 = _item$metadata2._promotion) === null || _item$metadata2 === void 0 ? void 0 : _item$metadata2.inPromotion) === true;
|
|
505
|
+
var existing = groups.get(key);
|
|
506
|
+
if (!existing) {
|
|
507
|
+
var mergedItem = cloneDeep(item);
|
|
508
|
+
var metadata = mergedItem.metadata || {};
|
|
509
|
+
delete metadata._promotion;
|
|
510
|
+
mergedItem.metadata = metadata;
|
|
511
|
+
if (Array.isArray(mergedItem.product_bundle)) {
|
|
512
|
+
var _iterator6 = _createForOfIteratorHelper(mergedItem.product_bundle),
|
|
513
|
+
_step6;
|
|
514
|
+
try {
|
|
515
|
+
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
|
516
|
+
var bundle = _step6.value;
|
|
517
|
+
if (bundle && _typeof(bundle) === 'object') delete bundle._promotion;
|
|
518
|
+
}
|
|
519
|
+
} catch (err) {
|
|
520
|
+
_iterator6.e(err);
|
|
521
|
+
} finally {
|
|
522
|
+
_iterator6.f();
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
if (wasInPromotion) {
|
|
526
|
+
mergedItem._wasInPromotionBeforeConsolidate = true;
|
|
527
|
+
}
|
|
528
|
+
groups.set(key, {
|
|
529
|
+
item: mergedItem,
|
|
530
|
+
originalListIndex: originalListIndex
|
|
531
|
+
});
|
|
532
|
+
continue;
|
|
533
|
+
}
|
|
534
|
+
existing.item.num = getSafeProductNum(Number(existing.item.num || 0) + Number(item.num || 0));
|
|
535
|
+
if (wasInPromotion) {
|
|
536
|
+
existing.item._wasInPromotionBeforeConsolidate = true;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
} catch (err) {
|
|
540
|
+
_iterator5.e(err);
|
|
541
|
+
} finally {
|
|
542
|
+
_iterator5.f();
|
|
543
|
+
}
|
|
544
|
+
return Array.from(groups.values());
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* X件Y元 整组凑满时按每组 x 件拆开展示(4 件 → 2 行各 2 件 $10)。
|
|
549
|
+
*
|
|
550
|
+
* @example
|
|
551
|
+
* splitXItemsPromoLinesByGroup(mergedLines, strategyActionMap);
|
|
552
|
+
*/
|
|
553
|
+
function splitXItemsPromoLinesByGroup(lines, strategyActionMap) {
|
|
554
|
+
var result = [];
|
|
555
|
+
var _iterator7 = _createForOfIteratorHelper(lines),
|
|
556
|
+
_step7;
|
|
557
|
+
try {
|
|
558
|
+
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
|
559
|
+
var _line$metadata13, _actionMeta$actionDet;
|
|
560
|
+
var line = _step7.value;
|
|
561
|
+
var promo = line === null || line === void 0 || (_line$metadata13 = line.metadata) === null || _line$metadata13 === void 0 ? void 0 : _line$metadata13._promotion;
|
|
562
|
+
if (!(promo !== null && promo !== void 0 && promo.inPromotion) || !promo.strategyId) {
|
|
563
|
+
result.push(line);
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
if (getPromotionActionType(promo) !== X_ITEMS_FOR_Y_PRICE) {
|
|
567
|
+
result.push(line);
|
|
568
|
+
continue;
|
|
569
|
+
}
|
|
570
|
+
var actionMeta = strategyActionMap.get(promo.strategyId);
|
|
571
|
+
var detail = (_actionMeta$actionDet = actionMeta === null || actionMeta === void 0 ? void 0 : actionMeta.actionDetail) !== null && _actionMeta$actionDet !== void 0 ? _actionMeta$actionDet : promo.actionDetail;
|
|
572
|
+
var x = Number(detail === null || detail === void 0 ? void 0 : detail.x);
|
|
573
|
+
var num = Number(line.num || 0);
|
|
574
|
+
var isCumulative = (detail === null || detail === void 0 ? void 0 : detail.cumulative) !== false;
|
|
575
|
+
if (!isCumulative || !Number.isFinite(x) || x <= 0 || num <= x || num % x !== 0) {
|
|
576
|
+
result.push(line);
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
var groupCount = num / x;
|
|
580
|
+
for (var i = 0; i < groupCount; i++) {
|
|
581
|
+
var splitLine = cloneDeep(line);
|
|
582
|
+
splitLine.num = getSafeProductNum(x);
|
|
583
|
+
splitLine.metadata = _objectSpread(_objectSpread({}, splitLine.metadata || {}), {}, {
|
|
584
|
+
unique_identification_number: createUuidV4()
|
|
585
|
+
});
|
|
586
|
+
result.push(splitLine);
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
} catch (err) {
|
|
590
|
+
_iterator7.e(err);
|
|
591
|
+
} finally {
|
|
592
|
+
_iterator7.f();
|
|
593
|
+
}
|
|
594
|
+
return result;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** 生成新 numeric id(仅用于评估器内部追踪) */
|
|
598
|
+
function generateNumericId() {
|
|
599
|
+
return Math.floor(Math.random() * 1000000000) + Date.now();
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* 把 OrderProduct 转成 evaluator 的 PromotionProduct(仅评估期使用)。
|
|
604
|
+
*
|
|
605
|
+
* 注意:评估器是「无状态、按 product_id + variant 组」工作的;这里给每行分配一个
|
|
606
|
+
* numericId 用于关联回原 OrderProduct(通过 originalItemMap)。
|
|
607
|
+
*/
|
|
608
|
+
function convertToPromotionProduct(product, index) {
|
|
609
|
+
var _product$product_id, _product$product_vari, _product$num;
|
|
610
|
+
var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
|
|
611
|
+
var numericId = generateNumericId();
|
|
612
|
+
var originalItem = product;
|
|
613
|
+
return {
|
|
614
|
+
id: numericId,
|
|
615
|
+
product_id: Number((_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : 0) || 0,
|
|
616
|
+
product_variant_id: Number((_product$product_vari = product === null || product === void 0 ? void 0 : product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0) || 0,
|
|
617
|
+
name: metadata.product_name || (product === null || product === void 0 ? void 0 : product.title) || '',
|
|
618
|
+
price: getOrderProductOriginalPriceForPromotion(product),
|
|
619
|
+
quantity: Number((_product$num = product === null || product === void 0 ? void 0 : product.num) !== null && _product$num !== void 0 ? _product$num : 1) || 1,
|
|
620
|
+
bundle: getProductBundleForEvaluator(product),
|
|
621
|
+
_originalItem: originalItem,
|
|
622
|
+
_originalId: getOrderProductUid(product),
|
|
623
|
+
_originalIndex: index
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// ============================================
|
|
628
|
+
// 主流程:processCartPromotion
|
|
629
|
+
// ============================================
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* 计算赠品差异化操作(toAdd / toReduce / toRemove)。
|
|
633
|
+
*
|
|
634
|
+
* 与 legacy `calculateGiftActions` 等价;唯一差别是行键从 `_id` 改成 `metadata.unique_identification_number`。
|
|
635
|
+
*/
|
|
636
|
+
function calculateGiftActions(gifts, existingGifts) {
|
|
637
|
+
var toAdd = [];
|
|
638
|
+
var toReduce = [];
|
|
639
|
+
var toRemove = [];
|
|
640
|
+
|
|
641
|
+
// 按 strategyId 分组现有赠品
|
|
642
|
+
var existingByStrategy = new Map();
|
|
643
|
+
var _iterator8 = _createForOfIteratorHelper(existingGifts),
|
|
644
|
+
_step8;
|
|
645
|
+
try {
|
|
646
|
+
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
|
647
|
+
var _getGiftInfo, _gift$num;
|
|
648
|
+
var gift = _step8.value;
|
|
649
|
+
var strategyId = (_getGiftInfo = getGiftInfo(gift)) === null || _getGiftInfo === void 0 ? void 0 : _getGiftInfo.strategyId;
|
|
650
|
+
if (!strategyId) continue;
|
|
651
|
+
var existing = existingByStrategy.get(strategyId);
|
|
652
|
+
var qty = Number((_gift$num = gift === null || gift === void 0 ? void 0 : gift.num) !== null && _gift$num !== void 0 ? _gift$num : 1) || 1;
|
|
653
|
+
if (existing) {
|
|
654
|
+
existing.items.push(gift);
|
|
655
|
+
existing.totalQuantity += qty;
|
|
656
|
+
} else {
|
|
657
|
+
existingByStrategy.set(strategyId, {
|
|
658
|
+
items: [gift],
|
|
659
|
+
totalQuantity: qty
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
} catch (err) {
|
|
664
|
+
_iterator8.e(err);
|
|
665
|
+
} finally {
|
|
666
|
+
_iterator8.f();
|
|
667
|
+
}
|
|
668
|
+
var processedStrategyIds = new Set();
|
|
669
|
+
var _iterator9 = _createForOfIteratorHelper(gifts),
|
|
670
|
+
_step9;
|
|
671
|
+
try {
|
|
672
|
+
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
|
673
|
+
var _existing$totalQuanti;
|
|
674
|
+
var giftInfo = _step9.value;
|
|
675
|
+
var _strategyId = giftInfo.strategyId,
|
|
676
|
+
strategyName = giftInfo.strategyName,
|
|
677
|
+
giftCount = giftInfo.giftCount,
|
|
678
|
+
giftOptions = giftInfo.giftOptions,
|
|
679
|
+
sourceProductIds = giftInfo.sourceProductIds;
|
|
680
|
+
processedStrategyIds.add(_strategyId);
|
|
681
|
+
var _existing = existingByStrategy.get(_strategyId);
|
|
682
|
+
var existingCount = (_existing$totalQuanti = _existing === null || _existing === void 0 ? void 0 : _existing.totalQuantity) !== null && _existing$totalQuanti !== void 0 ? _existing$totalQuanti : 0;
|
|
683
|
+
var diff = giftCount - existingCount;
|
|
684
|
+
if (diff > 0) {
|
|
685
|
+
var _getGiftInfo2, _existing$items;
|
|
686
|
+
// 判断「用户手动减赠品」: 若评估器的 giftCount 没变,diff>0 说明是手动减,跳过补回
|
|
687
|
+
var lastEvaluated = (_getGiftInfo2 = getGiftInfo(_existing === null || _existing === void 0 || (_existing$items = _existing.items) === null || _existing$items === void 0 ? void 0 : _existing$items[0])) === null || _getGiftInfo2 === void 0 ? void 0 : _getGiftInfo2.lastEvaluatedGiftCount;
|
|
688
|
+
var strategyChanged = lastEvaluated === undefined || giftCount !== lastEvaluated;
|
|
689
|
+
if (strategyChanged) {
|
|
690
|
+
toAdd.push({
|
|
691
|
+
strategyId: _strategyId,
|
|
692
|
+
strategyName: strategyName,
|
|
693
|
+
giftCount: diff,
|
|
694
|
+
giftOptions: giftOptions,
|
|
695
|
+
sourceProductIds: sourceProductIds
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
} else if (diff < 0) {
|
|
699
|
+
// 减赠品:后进先出
|
|
700
|
+
var remaining = Math.abs(diff);
|
|
701
|
+
var reduceItems = [];
|
|
702
|
+
var removeIds = [];
|
|
703
|
+
var reversed = _toConsumableArray((_existing === null || _existing === void 0 ? void 0 : _existing.items) || []).reverse();
|
|
704
|
+
var _iterator11 = _createForOfIteratorHelper(reversed),
|
|
705
|
+
_step11;
|
|
706
|
+
try {
|
|
707
|
+
for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
|
|
708
|
+
var _giftItem$num;
|
|
709
|
+
var giftItem = _step11.value;
|
|
710
|
+
if (remaining <= 0) break;
|
|
711
|
+
var uid = getOrderProductUid(giftItem);
|
|
712
|
+
var _qty = Number((_giftItem$num = giftItem === null || giftItem === void 0 ? void 0 : giftItem.num) !== null && _giftItem$num !== void 0 ? _giftItem$num : 1) || 1;
|
|
713
|
+
if (_qty <= remaining) {
|
|
714
|
+
removeIds.push(uid);
|
|
715
|
+
remaining -= _qty;
|
|
716
|
+
} else {
|
|
717
|
+
reduceItems.push({
|
|
718
|
+
uid: uid,
|
|
719
|
+
currentQuantity: _qty,
|
|
720
|
+
newQuantity: _qty - remaining
|
|
721
|
+
});
|
|
722
|
+
remaining = 0;
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
} catch (err) {
|
|
726
|
+
_iterator11.e(err);
|
|
727
|
+
} finally {
|
|
728
|
+
_iterator11.f();
|
|
729
|
+
}
|
|
730
|
+
if (reduceItems.length > 0) toReduce.push({
|
|
731
|
+
strategyId: _strategyId,
|
|
732
|
+
items: reduceItems
|
|
733
|
+
});
|
|
734
|
+
toRemove.push.apply(toRemove, removeIds);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// 失效策略的赠品:全部 remove
|
|
739
|
+
} catch (err) {
|
|
740
|
+
_iterator9.e(err);
|
|
741
|
+
} finally {
|
|
742
|
+
_iterator9.f();
|
|
743
|
+
}
|
|
744
|
+
var _iterator10 = _createForOfIteratorHelper(existingByStrategy),
|
|
745
|
+
_step10;
|
|
746
|
+
try {
|
|
747
|
+
for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
|
|
748
|
+
var _step10$value = _slicedToArray(_step10.value, 2),
|
|
749
|
+
_strategyId2 = _step10$value[0],
|
|
750
|
+
_existing2 = _step10$value[1];
|
|
751
|
+
if (processedStrategyIds.has(_strategyId2)) continue;
|
|
752
|
+
var _iterator12 = _createForOfIteratorHelper(_existing2.items),
|
|
753
|
+
_step12;
|
|
754
|
+
try {
|
|
755
|
+
for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
|
|
756
|
+
var _giftItem = _step12.value;
|
|
757
|
+
toRemove.push(getOrderProductUid(_giftItem));
|
|
758
|
+
}
|
|
759
|
+
} catch (err) {
|
|
760
|
+
_iterator12.e(err);
|
|
761
|
+
} finally {
|
|
762
|
+
_iterator12.f();
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
} catch (err) {
|
|
766
|
+
_iterator10.e(err);
|
|
767
|
+
} finally {
|
|
768
|
+
_iterator10.f();
|
|
769
|
+
}
|
|
770
|
+
return {
|
|
771
|
+
toAdd: toAdd,
|
|
772
|
+
toReduce: toReduce,
|
|
773
|
+
toRemove: toRemove
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* 从策略配置的 product_match 规则提取可参与商品列表。
|
|
779
|
+
*
|
|
780
|
+
* @example
|
|
781
|
+
* extractProductMatchIdentifiersFromStrategyConfig(strategyConfig);
|
|
782
|
+
* // => [{ product_id: 60736, product_variant_id: 0 }]
|
|
783
|
+
*/
|
|
784
|
+
export function extractProductMatchIdentifiersFromStrategyConfig(strategyConfig) {
|
|
785
|
+
var _strategyConfig$condi;
|
|
786
|
+
var rules = strategyConfig === null || strategyConfig === void 0 || (_strategyConfig$condi = strategyConfig.conditions) === null || _strategyConfig$condi === void 0 ? void 0 : _strategyConfig$condi.rules;
|
|
787
|
+
if (!Array.isArray(rules)) return [];
|
|
788
|
+
var _iterator13 = _createForOfIteratorHelper(rules),
|
|
789
|
+
_step13;
|
|
790
|
+
try {
|
|
791
|
+
for (_iterator13.s(); !(_step13 = _iterator13.n()).done;) {
|
|
792
|
+
var rule = _step13.value;
|
|
793
|
+
if ((rule === null || rule === void 0 ? void 0 : rule.field) === 'productIdAndVariantId' && ((rule === null || rule === void 0 ? void 0 : rule.operator) === 'product_match' || (rule === null || rule === void 0 ? void 0 : rule.operator) === 'object_in') && Array.isArray(rule === null || rule === void 0 ? void 0 : rule.value)) {
|
|
794
|
+
return rule.value.map(function (item) {
|
|
795
|
+
return {
|
|
796
|
+
product_id: Number(item === null || item === void 0 ? void 0 : item.product_id) || 0,
|
|
797
|
+
product_variant_id: Number(item === null || item === void 0 ? void 0 : item.product_variant_id) || 0
|
|
798
|
+
};
|
|
799
|
+
}).filter(function (item) {
|
|
800
|
+
return item.product_id > 0;
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
} catch (err) {
|
|
805
|
+
_iterator13.e(err);
|
|
806
|
+
} finally {
|
|
807
|
+
_iterator13.f();
|
|
808
|
+
}
|
|
809
|
+
return [];
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* 解析策略凑单所需件数(evaluator 原始返回可能不含 requiredQuantity)。
|
|
814
|
+
*
|
|
815
|
+
* @example
|
|
816
|
+
* resolveStrategyRequiredQuantity({ actionType: 'X_ITEMS_FOR_Y_PRICE', actionDetail: { x: 2 } });
|
|
817
|
+
*/
|
|
818
|
+
export function resolveStrategyRequiredQuantity(matched) {
|
|
819
|
+
var preset = Number(matched.requiredQuantity);
|
|
820
|
+
if (Number.isFinite(preset) && preset > 0) return preset;
|
|
821
|
+
var detail = matched.actionDetail || {};
|
|
822
|
+
if (matched.actionType === 'X_ITEMS_FOR_Y_PRICE') {
|
|
823
|
+
return Number(detail.x) || 2;
|
|
824
|
+
}
|
|
825
|
+
if (matched.actionType === 'BUY_X_GET_Y_FREE') {
|
|
826
|
+
return Number(detail.buyQuantity) || 1;
|
|
827
|
+
}
|
|
828
|
+
return 1;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* 解析 Browse Items 弹窗候选商品(优先 eligibleProducts,否则读 strategyConfig)。
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* resolveStrategyEligibleProducts(matchedStrategy);
|
|
836
|
+
*/
|
|
837
|
+
export function resolveStrategyEligibleProducts(matched) {
|
|
838
|
+
if (Array.isArray(matched.eligibleProducts) && matched.eligibleProducts.length > 0) {
|
|
839
|
+
return matched.eligibleProducts;
|
|
840
|
+
}
|
|
841
|
+
return extractProductMatchIdentifiersFromStrategyConfig(matched.strategyConfig);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
/**
|
|
845
|
+
* 计算未满足促销条件(用于购物车底部「再买 N 件即可享受 XX」alert)。
|
|
846
|
+
*
|
|
847
|
+
* 数据源:商品的 `metadata._promotion.inPromotion === false`(来自 processCartPromotion
|
|
848
|
+
* 第 8 步追加的「有适用策略但当前未参与促销」标记)。
|
|
849
|
+
*/
|
|
850
|
+
export function calculateUnfulfilledPromotions(processedProducts, applicableStrategiesResult, mainProducts) {
|
|
851
|
+
var unfulfilledMap = new Map();
|
|
852
|
+
var _loop2 = function _loop2() {
|
|
853
|
+
var _product$metadata4, _ref13, _product$_originalPro, _product$metadata5, _product$num2;
|
|
854
|
+
var product = processedProducts[i];
|
|
855
|
+
var promotion = product === null || product === void 0 || (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4._promotion;
|
|
856
|
+
if (!promotion || promotion.inPromotion !== false) return 0; // continue
|
|
857
|
+
var strategyId = promotion.strategyId;
|
|
858
|
+
if (!strategyId) return 0; // continue
|
|
859
|
+
var lookupUid = String((_ref13 = (_product$_originalPro = product === null || product === void 0 ? void 0 : product._originalProductUid) !== null && _product$_originalPro !== void 0 ? _product$_originalPro : product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) !== null && _ref13 !== void 0 ? _ref13 : '');
|
|
860
|
+
var originalIndex = mainProducts.findIndex(function (item) {
|
|
861
|
+
return getOrderProductUid(item) === lookupUid;
|
|
862
|
+
});
|
|
863
|
+
if (originalIndex === -1) return 0; // continue
|
|
864
|
+
var strategyData = applicableStrategiesResult[originalIndex];
|
|
865
|
+
if (!strategyData || !strategyData.hasApplicableStrategy) return 0; // continue
|
|
866
|
+
var matched = strategyData.applicableStrategies.find(function (s) {
|
|
867
|
+
return s.strategyId === strategyId;
|
|
868
|
+
});
|
|
869
|
+
if (!matched) return 0; // continue
|
|
870
|
+
var quantity = Number((_product$num2 = product === null || product === void 0 ? void 0 : product.num) !== null && _product$num2 !== void 0 ? _product$num2 : 1) || 1;
|
|
871
|
+
if (unfulfilledMap.has(strategyId)) {
|
|
872
|
+
unfulfilledMap.get(strategyId).currentQuantity += quantity;
|
|
873
|
+
} else {
|
|
874
|
+
unfulfilledMap.set(strategyId, {
|
|
875
|
+
strategyId: strategyId,
|
|
876
|
+
strategyName: matched.strategyName,
|
|
877
|
+
actionType: matched.actionType,
|
|
878
|
+
currentQuantity: quantity,
|
|
879
|
+
requiredQuantity: resolveStrategyRequiredQuantity(matched),
|
|
880
|
+
needQuantity: 0,
|
|
881
|
+
eligibleProducts: resolveStrategyEligibleProducts(matched),
|
|
882
|
+
strategyMetadata: matched.strategyMetadata,
|
|
883
|
+
display: matched.display
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
},
|
|
887
|
+
_ret;
|
|
888
|
+
for (var i = 0; i < processedProducts.length; i++) {
|
|
889
|
+
_ret = _loop2();
|
|
890
|
+
if (_ret === 0) continue;
|
|
891
|
+
}
|
|
892
|
+
var result = [];
|
|
893
|
+
var _iterator14 = _createForOfIteratorHelper(unfulfilledMap.values()),
|
|
894
|
+
_step14;
|
|
895
|
+
try {
|
|
896
|
+
for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
|
|
897
|
+
var data = _step14.value;
|
|
898
|
+
var needQuantity = data.requiredQuantity - data.currentQuantity;
|
|
899
|
+
if (needQuantity > 0) {
|
|
900
|
+
result.push(_objectSpread(_objectSpread({}, data), {}, {
|
|
901
|
+
needQuantity: needQuantity
|
|
902
|
+
}));
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
} catch (err) {
|
|
906
|
+
_iterator14.e(err);
|
|
907
|
+
} finally {
|
|
908
|
+
_iterator14.f();
|
|
909
|
+
}
|
|
910
|
+
return result;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* 给商品列表追加促销标签(写入 `metadata._promotionTags`),供 ProductCard 渲染。
|
|
915
|
+
*
|
|
916
|
+
* - 没有适用策略的商品会清除 `_promotionTags`(避免脏数据)。
|
|
917
|
+
* - 仅基于 product_id 匹配(matchVariant=false),与商品卡通用场景对齐。
|
|
918
|
+
*
|
|
919
|
+
* @example
|
|
920
|
+
* const list = appendPromotionTags(catalog, evaluator);
|
|
921
|
+
* // list[i].metadata._promotionTags = [{ text, type, strategyId }]
|
|
922
|
+
*/
|
|
923
|
+
export function appendPromotionTags(products, evaluator) {
|
|
924
|
+
if (!Array.isArray(products) || products.length === 0 || !evaluator) {
|
|
925
|
+
return products || [];
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// 评估器期望的 product shape,最少字段集
|
|
929
|
+
var evaluatorInput = products.map(function (item, index) {
|
|
930
|
+
var _ref14, _item$id, _item$product_variant4, _item$price, _item$quantity;
|
|
931
|
+
return {
|
|
932
|
+
id: index,
|
|
933
|
+
product_id: Number((_ref14 = (_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.product_id) !== null && _ref14 !== void 0 ? _ref14 : 0) || 0,
|
|
934
|
+
product_variant_id: Number((_item$product_variant4 = item === null || item === void 0 ? void 0 : item.product_variant_id) !== null && _item$product_variant4 !== void 0 ? _item$product_variant4 : 0) || 0,
|
|
935
|
+
name: (item === null || item === void 0 ? void 0 : item.title) || (item === null || item === void 0 ? void 0 : item.name) || '',
|
|
936
|
+
price: Number((_item$price = item === null || item === void 0 ? void 0 : item.price) !== null && _item$price !== void 0 ? _item$price : 0) || 0,
|
|
937
|
+
quantity: Number((_item$quantity = item === null || item === void 0 ? void 0 : item.quantity) !== null && _item$quantity !== void 0 ? _item$quantity : 1) || 1,
|
|
938
|
+
bundle: []
|
|
939
|
+
};
|
|
940
|
+
});
|
|
941
|
+
var strategies = evaluator.getProductsApplicableStrategies({
|
|
942
|
+
products: evaluatorInput
|
|
943
|
+
}, false);
|
|
944
|
+
return products.map(function (item, index) {
|
|
945
|
+
var data = strategies[index];
|
|
946
|
+
var tags = [];
|
|
947
|
+
if (data !== null && data !== void 0 && data.hasApplicableStrategy) {
|
|
948
|
+
var _iterator15 = _createForOfIteratorHelper(data.applicableStrategies),
|
|
949
|
+
_step15;
|
|
950
|
+
try {
|
|
951
|
+
for (_iterator15.s(); !(_step15 = _iterator15.n()).done;) {
|
|
952
|
+
var strategy = _step15.value;
|
|
953
|
+
if (strategy.display) {
|
|
954
|
+
tags.push({
|
|
955
|
+
text: strategy.display.text,
|
|
956
|
+
type: strategy.display.type,
|
|
957
|
+
strategyId: strategy.strategyId
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
} catch (err) {
|
|
962
|
+
_iterator15.e(err);
|
|
963
|
+
} finally {
|
|
964
|
+
_iterator15.f();
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
// 商品卡兼容两种位置:顶层 `_promotionTags` 与 `metadata._promotionTags`
|
|
968
|
+
// ProductCard 现有实现读顶层(详见 productSelect/ProductCard/index.tsx),
|
|
969
|
+
// 此处同时写顶层以保持视图直连;OrderProduct 行版本走 metadata(避免顶层非协议字段)。
|
|
970
|
+
if (tags.length === 0) {
|
|
971
|
+
var _ref15 = item,
|
|
972
|
+
_promotionTags = _ref15._promotionTags,
|
|
973
|
+
rest = _objectWithoutProperties(_ref15, _excluded);
|
|
974
|
+
void _promotionTags;
|
|
975
|
+
return rest;
|
|
976
|
+
}
|
|
977
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
978
|
+
_promotionTags: tags
|
|
979
|
+
});
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* 处理购物车的促销计算与赠品差异化。
|
|
985
|
+
*
|
|
986
|
+
* 流程:
|
|
987
|
+
* 1. 分离 main / gift / edit-product 三类(带 `booking_id` 的编辑态商品不参与促销)
|
|
988
|
+
* 2. 转 PromotionProduct 喂评估器 → 拿到 `evaluateCartWithPricing` 与 `getProductsApplicableStrategies`
|
|
989
|
+
* 3. 把 PricedProduct 映射回 OrderProduct 形态:
|
|
990
|
+
* - 参与促销的,写 `metadata._promotion` + 调整 `selling_price` / `main_product_selling_price`
|
|
991
|
+
* - 拆分的,生成新 uid,复制原行其它字段
|
|
992
|
+
* 4. 计算 `_giftInfo` 挂主商品(每个策略首个主商品)
|
|
993
|
+
* 5. 计算 `giftActions`(toAdd / toReduce / toRemove)
|
|
994
|
+
* 6. 计算 `unfulfilledPromotions`
|
|
995
|
+
*
|
|
996
|
+
* @example
|
|
997
|
+
* const { products, giftActions, unfulfilledPromotions } = processCartPromotion(
|
|
998
|
+
* tempOrder.products,
|
|
999
|
+
* evaluator,
|
|
1000
|
+
* );
|
|
1001
|
+
*/
|
|
1002
|
+
export function processCartPromotion(list, evaluator, options) {
|
|
1003
|
+
var empty = {
|
|
1004
|
+
products: Array.isArray(list) ? _toConsumableArray(list) : [],
|
|
1005
|
+
totalDiscount: 0,
|
|
1006
|
+
gifts: [],
|
|
1007
|
+
giftActions: {
|
|
1008
|
+
toAdd: [],
|
|
1009
|
+
toReduce: [],
|
|
1010
|
+
toRemove: []
|
|
1011
|
+
},
|
|
1012
|
+
unfulfilledPromotions: []
|
|
1013
|
+
};
|
|
1014
|
+
if (!list || list.length === 0 || !evaluator) return empty;
|
|
1015
|
+
|
|
1016
|
+
// 0. 分类
|
|
1017
|
+
var mainProductsWithIndex = [];
|
|
1018
|
+
var existingGiftsWithIndex = [];
|
|
1019
|
+
var editProductsWithIndex = [];
|
|
1020
|
+
for (var i = 0; i < list.length; i++) {
|
|
1021
|
+
var item = list[i];
|
|
1022
|
+
var giftInfo = getGiftInfo(item);
|
|
1023
|
+
if (isPersistedGeneratedVoucher(item)) {
|
|
1024
|
+
editProductsWithIndex.push({
|
|
1025
|
+
item: item,
|
|
1026
|
+
originalListIndex: i
|
|
1027
|
+
});
|
|
1028
|
+
} else if (giftInfo) {
|
|
1029
|
+
existingGiftsWithIndex.push({
|
|
1030
|
+
item: item,
|
|
1031
|
+
originalListIndex: i
|
|
1032
|
+
});
|
|
1033
|
+
} else if ((item === null || item === void 0 ? void 0 : item.booking_id) !== undefined && (item === null || item === void 0 ? void 0 : item.booking_id) !== null && item.booking_id !== 0 && item.booking_id !== '0') {
|
|
1034
|
+
editProductsWithIndex.push({
|
|
1035
|
+
item: item,
|
|
1036
|
+
originalListIndex: i
|
|
1037
|
+
});
|
|
1038
|
+
} else {
|
|
1039
|
+
mainProductsWithIndex.push({
|
|
1040
|
+
item: item,
|
|
1041
|
+
originalListIndex: i
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
var consolidatedMainProductsWithIndex = consolidateMainProductsForPromotion(mainProductsWithIndex);
|
|
1046
|
+
var mainProducts = consolidatedMainProductsWithIndex.map(function (x) {
|
|
1047
|
+
return x.item;
|
|
1048
|
+
});
|
|
1049
|
+
var existingGifts = existingGiftsWithIndex.map(function (x) {
|
|
1050
|
+
return x.item;
|
|
1051
|
+
});
|
|
1052
|
+
if (mainProducts.length === 0) {
|
|
1053
|
+
var editProducts = editProductsWithIndex.map(function (x) {
|
|
1054
|
+
return x.item;
|
|
1055
|
+
});
|
|
1056
|
+
if (existingGifts.length > 0) {
|
|
1057
|
+
var toRemove = [];
|
|
1058
|
+
var _iterator16 = _createForOfIteratorHelper(existingGifts),
|
|
1059
|
+
_step16;
|
|
1060
|
+
try {
|
|
1061
|
+
for (_iterator16.s(); !(_step16 = _iterator16.n()).done;) {
|
|
1062
|
+
var gift = _step16.value;
|
|
1063
|
+
var uid = getOrderProductUid(gift);
|
|
1064
|
+
if (uid) toRemove.push(uid);
|
|
1065
|
+
}
|
|
1066
|
+
} catch (err) {
|
|
1067
|
+
_iterator16.e(err);
|
|
1068
|
+
} finally {
|
|
1069
|
+
_iterator16.f();
|
|
1070
|
+
}
|
|
1071
|
+
return {
|
|
1072
|
+
products: editProducts,
|
|
1073
|
+
totalDiscount: 0,
|
|
1074
|
+
gifts: [],
|
|
1075
|
+
giftActions: {
|
|
1076
|
+
toAdd: [],
|
|
1077
|
+
toReduce: [],
|
|
1078
|
+
toRemove: toRemove
|
|
1079
|
+
},
|
|
1080
|
+
unfulfilledPromotions: []
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
return _objectSpread(_objectSpread({}, empty), {}, {
|
|
1084
|
+
products: editProducts.length > 0 ? editProducts : _toConsumableArray(list)
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
// 1. 转 PromotionProduct
|
|
1089
|
+
var promotionProducts = [];
|
|
1090
|
+
var originalItemMap = new Map();
|
|
1091
|
+
var productsForStrategies = consolidatedMainProductsWithIndex.map(function (_ref16, i) {
|
|
1092
|
+
var _item$product_id, _item$product_variant5, _item$metadata3, _item$num;
|
|
1093
|
+
var item = _ref16.item;
|
|
1094
|
+
return {
|
|
1095
|
+
id: i,
|
|
1096
|
+
product_id: Number((_item$product_id = item === null || item === void 0 ? void 0 : item.product_id) !== null && _item$product_id !== void 0 ? _item$product_id : 0) || 0,
|
|
1097
|
+
product_variant_id: Number((_item$product_variant5 = item === null || item === void 0 ? void 0 : item.product_variant_id) !== null && _item$product_variant5 !== void 0 ? _item$product_variant5 : 0) || 0,
|
|
1098
|
+
name: (item === null || item === void 0 || (_item$metadata3 = item.metadata) === null || _item$metadata3 === void 0 ? void 0 : _item$metadata3.product_name) || (item === null || item === void 0 ? void 0 : item.title) || '',
|
|
1099
|
+
price: getOrderProductBasePrice(item),
|
|
1100
|
+
quantity: Number((_item$num = item === null || item === void 0 ? void 0 : item.num) !== null && _item$num !== void 0 ? _item$num : 1) || 1,
|
|
1101
|
+
bundle: getProductBundleForEvaluator(item)
|
|
1102
|
+
};
|
|
1103
|
+
});
|
|
1104
|
+
for (var _i = 0; _i < consolidatedMainProductsWithIndex.length; _i++) {
|
|
1105
|
+
var _consolidatedMainProd = consolidatedMainProductsWithIndex[_i],
|
|
1106
|
+
_item = _consolidatedMainProd.item,
|
|
1107
|
+
originalListIndex = _consolidatedMainProd.originalListIndex;
|
|
1108
|
+
var promotionProduct = convertToPromotionProduct(_item, originalListIndex);
|
|
1109
|
+
promotionProducts.push(promotionProduct);
|
|
1110
|
+
originalItemMap.set(promotionProduct.id, {
|
|
1111
|
+
item: _item,
|
|
1112
|
+
index: originalListIndex
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
// 2. 拿适用策略
|
|
1117
|
+
var applicableStrategiesResult = evaluator.getProductsApplicableStrategies({
|
|
1118
|
+
products: productsForStrategies,
|
|
1119
|
+
channel: options === null || options === void 0 ? void 0 : options.channel
|
|
1120
|
+
});
|
|
1121
|
+
var strategyActionMap = new Map();
|
|
1122
|
+
var _iterator17 = _createForOfIteratorHelper(applicableStrategiesResult || []),
|
|
1123
|
+
_step17;
|
|
1124
|
+
try {
|
|
1125
|
+
for (_iterator17.s(); !(_step17 = _iterator17.n()).done;) {
|
|
1126
|
+
var row = _step17.value;
|
|
1127
|
+
var _iterator22 = _createForOfIteratorHelper((row === null || row === void 0 ? void 0 : row.applicableStrategies) || []),
|
|
1128
|
+
_step22;
|
|
1129
|
+
try {
|
|
1130
|
+
for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
|
|
1131
|
+
var strategy = _step22.value;
|
|
1132
|
+
if (!(strategy !== null && strategy !== void 0 && strategy.strategyId)) continue;
|
|
1133
|
+
strategyActionMap.set(strategy.strategyId, {
|
|
1134
|
+
actionType: strategy.actionType,
|
|
1135
|
+
actionDetail: strategy.actionDetail
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
} catch (err) {
|
|
1139
|
+
_iterator22.e(err);
|
|
1140
|
+
} finally {
|
|
1141
|
+
_iterator22.f();
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
// 3. 评估器
|
|
1146
|
+
} catch (err) {
|
|
1147
|
+
_iterator17.e(err);
|
|
1148
|
+
} finally {
|
|
1149
|
+
_iterator17.f();
|
|
1150
|
+
}
|
|
1151
|
+
var result = evaluator.evaluateCartWithPricing({
|
|
1152
|
+
products: promotionProducts,
|
|
1153
|
+
channel: options === null || options === void 0 ? void 0 : options.channel
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
// 4. 收集每个策略的 sourceProductIds(参与策略的主商品 uid)
|
|
1157
|
+
var strategySourceProductIds = new Map();
|
|
1158
|
+
var _iterator18 = _createForOfIteratorHelper(result.products),
|
|
1159
|
+
_step18;
|
|
1160
|
+
try {
|
|
1161
|
+
for (_iterator18.s(); !(_step18 = _iterator18.n()).done;) {
|
|
1162
|
+
var priced = _step18.value;
|
|
1163
|
+
if (priced.inPromotion && priced.strategyId) {
|
|
1164
|
+
var _priced$originalId;
|
|
1165
|
+
var sourceId = (_priced$originalId = priced.originalId) !== null && _priced$originalId !== void 0 ? _priced$originalId : priced.id;
|
|
1166
|
+
var originalData = originalItemMap.get(sourceId);
|
|
1167
|
+
if (originalData) {
|
|
1168
|
+
var _uid = getOrderProductUid(originalData.item);
|
|
1169
|
+
if (!_uid) continue;
|
|
1170
|
+
var arr = strategySourceProductIds.get(priced.strategyId) || [];
|
|
1171
|
+
if (!arr.includes(_uid)) arr.push(_uid);
|
|
1172
|
+
strategySourceProductIds.set(priced.strategyId, arr);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// 5. 扩展 gifts,加 sourceProductIds
|
|
1178
|
+
} catch (err) {
|
|
1179
|
+
_iterator18.e(err);
|
|
1180
|
+
} finally {
|
|
1181
|
+
_iterator18.f();
|
|
1182
|
+
}
|
|
1183
|
+
var extendedGifts = result.gifts.map(function (gift) {
|
|
1184
|
+
return _objectSpread(_objectSpread({}, gift), {}, {
|
|
1185
|
+
sourceProductIds: strategySourceProductIds.get(gift.strategyId) || []
|
|
1186
|
+
});
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1189
|
+
// 6. PricedProduct → OrderProduct(含拆分与价格调整)
|
|
1190
|
+
var strategyGiftInfoMap = new Map();
|
|
1191
|
+
var _iterator19 = _createForOfIteratorHelper(extendedGifts),
|
|
1192
|
+
_step19;
|
|
1193
|
+
try {
|
|
1194
|
+
for (_iterator19.s(); !(_step19 = _iterator19.n()).done;) {
|
|
1195
|
+
var _gift = _step19.value;
|
|
1196
|
+
strategyGiftInfoMap.set(_gift.strategyId, _gift);
|
|
1197
|
+
}
|
|
1198
|
+
} catch (err) {
|
|
1199
|
+
_iterator19.e(err);
|
|
1200
|
+
} finally {
|
|
1201
|
+
_iterator19.f();
|
|
1202
|
+
}
|
|
1203
|
+
var strategyGiftInfoOwner = new Map();
|
|
1204
|
+
var processedProducts = [];
|
|
1205
|
+
var _iterator20 = _createForOfIteratorHelper(result.products),
|
|
1206
|
+
_step20;
|
|
1207
|
+
try {
|
|
1208
|
+
for (_iterator20.s(); !(_step20 = _iterator20.n()).done;) {
|
|
1209
|
+
var _priced$originalId2, _priced$product_id, _originalItem$product, _metadata$_promotion2;
|
|
1210
|
+
var _priced = _step20.value;
|
|
1211
|
+
var rawSourceId = (_priced$originalId2 = _priced.originalId) !== null && _priced$originalId2 !== void 0 ? _priced$originalId2 : _priced.id;
|
|
1212
|
+
var _sourceId = Number(rawSourceId);
|
|
1213
|
+
var _originalData = Number.isFinite(_sourceId) ? originalItemMap.get(_sourceId) : undefined;
|
|
1214
|
+
if (!_originalData) continue;
|
|
1215
|
+
var originalItem = _originalData.item,
|
|
1216
|
+
originalIndex = _originalData.index;
|
|
1217
|
+
var pricedProductId = Number((_priced$product_id = _priced.product_id) !== null && _priced$product_id !== void 0 ? _priced$product_id : 0);
|
|
1218
|
+
var originalProductId = Number((_originalItem$product = originalItem.product_id) !== null && _originalItem$product !== void 0 ? _originalItem$product : 0);
|
|
1219
|
+
if (pricedProductId > 0 && originalProductId > 0 && pricedProductId !== originalProductId) {
|
|
1220
|
+
continue;
|
|
1221
|
+
}
|
|
1222
|
+
var newItem = cloneDeep(originalItem);
|
|
1223
|
+
var metadata = newItem.metadata || {};
|
|
1224
|
+
var sourceCartNum = getSafeProductNum(originalItem.num);
|
|
1225
|
+
newItem._sourceCartNum = sourceCartNum;
|
|
1226
|
+
|
|
1227
|
+
// 清掉历史促销字段
|
|
1228
|
+
var wasInPromotion = ((_metadata$_promotion2 = metadata._promotion) === null || _metadata$_promotion2 === void 0 ? void 0 : _metadata$_promotion2.inPromotion) === true || originalItem._wasInPromotionBeforeConsolidate === true;
|
|
1229
|
+
delete metadata._promotion;
|
|
1230
|
+
if (Array.isArray(newItem.product_bundle)) {
|
|
1231
|
+
var _iterator23 = _createForOfIteratorHelper(newItem.product_bundle),
|
|
1232
|
+
_step23;
|
|
1233
|
+
try {
|
|
1234
|
+
for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
|
|
1235
|
+
var b = _step23.value;
|
|
1236
|
+
if (b && _typeof(b) === 'object') delete b._promotion;
|
|
1237
|
+
}
|
|
1238
|
+
} catch (err) {
|
|
1239
|
+
_iterator23.e(err);
|
|
1240
|
+
} finally {
|
|
1241
|
+
_iterator23.f();
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
var originalBasePrice = getOrderProductOriginalPriceForPromotion(originalItem);
|
|
1245
|
+
var shouldModifyPrice = _priced.inPromotion || wasInPromotion;
|
|
1246
|
+
var priceUnchangedPromo = _priced.inPromotion && Number(_priced.finalPrice) === Number(originalBasePrice);
|
|
1247
|
+
if (shouldModifyPrice) {
|
|
1248
|
+
if (_priced.inPromotion && !priceUnchangedPromo) {
|
|
1249
|
+
var _priced$strategyMetad;
|
|
1250
|
+
var promoUnitPrice = new Decimal(_priced.finalPrice).toDecimalPlaces(2).toFixed(2);
|
|
1251
|
+
applyPromoUnitPriceToLine(newItem, {
|
|
1252
|
+
promoUnitPrice: promoUnitPrice,
|
|
1253
|
+
originalBasePrice: originalBasePrice,
|
|
1254
|
+
strategyTitle: (_priced$strategyMetad = _priced.strategyMetadata) === null || _priced$strategyMetad === void 0 ? void 0 : _priced$strategyMetad.name
|
|
1255
|
+
});
|
|
1256
|
+
} else {
|
|
1257
|
+
// 撤销上一轮促销:还原 selling_price 到 main_product_original_price 派生值
|
|
1258
|
+
var optionSum = sumOptionUnitPrice(getProductSkuOptions(newItem)).toNumber();
|
|
1259
|
+
var sourceRestore = new Decimal(originalBasePrice).toDecimalPlaces(2).toFixed(2);
|
|
1260
|
+
var mainRestore = new Decimal(Number(sourceRestore) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
|
|
1261
|
+
metadata.source_product_price = sourceRestore;
|
|
1262
|
+
metadata.main_product_selling_price = mainRestore;
|
|
1263
|
+
metadata.price_schema_version = 2;
|
|
1264
|
+
newItem.selling_price = composeLinePrice({
|
|
1265
|
+
mainPrice: mainRestore,
|
|
1266
|
+
bundle: newItem.product_bundle
|
|
1267
|
+
});
|
|
1268
|
+
updatePromotionDiscountList(newItem, null);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
newItem.num = _priced.isSplit ? getSafeProductNum(_priced.quantity) : sourceCartNum;
|
|
1272
|
+
|
|
1273
|
+
// 拆分行:生成新 uid,复制原行
|
|
1274
|
+
if (_priced.isSplit) {
|
|
1275
|
+
metadata.unique_identification_number = createUuidV4();
|
|
1276
|
+
}
|
|
1277
|
+
if (_priced.strategyId) {
|
|
1278
|
+
var actionMeta = strategyActionMap.get(_priced.strategyId);
|
|
1279
|
+
var promotionInfo = {
|
|
1280
|
+
strategyId: _priced.strategyId,
|
|
1281
|
+
strategyMetadata: _priced.strategyMetadata,
|
|
1282
|
+
inPromotion: _priced.inPromotion,
|
|
1283
|
+
originalPrice: originalBasePrice,
|
|
1284
|
+
finalPrice: _priced.finalPrice,
|
|
1285
|
+
actionType: actionMeta === null || actionMeta === void 0 ? void 0 : actionMeta.actionType,
|
|
1286
|
+
actionDetail: actionMeta === null || actionMeta === void 0 ? void 0 : actionMeta.actionDetail
|
|
1287
|
+
};
|
|
1288
|
+
var bundleIdx = _priced.matchedBundleIndex;
|
|
1289
|
+
if (bundleIdx !== undefined && Array.isArray(newItem.product_bundle) && newItem.product_bundle[bundleIdx]) {
|
|
1290
|
+
newItem.product_bundle[bundleIdx]._promotion = promotionInfo;
|
|
1291
|
+
} else {
|
|
1292
|
+
metadata._promotion = promotionInfo;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
newItem.metadata = metadata;
|
|
1296
|
+
|
|
1297
|
+
// 5.1 第一个参与「买X送Y」策略的主商品,挂 giftInfo
|
|
1298
|
+
if (_priced.inPromotion && _priced.strategyId) {
|
|
1299
|
+
var _gift2 = strategyGiftInfoMap.get(_priced.strategyId);
|
|
1300
|
+
if (_gift2 && Array.isArray(_gift2.giftOptions) && _gift2.giftOptions.length > 0 && !strategyGiftInfoOwner.has(_priced.strategyId)) {
|
|
1301
|
+
var _newItem$product_bund;
|
|
1302
|
+
var giftInfoData = {
|
|
1303
|
+
strategyName: _gift2.strategyName,
|
|
1304
|
+
giftCount: _gift2.giftCount,
|
|
1305
|
+
giftOptions: _gift2.giftOptions
|
|
1306
|
+
};
|
|
1307
|
+
var _bundleIdx = _priced.matchedBundleIndex;
|
|
1308
|
+
if (_bundleIdx !== undefined && Array.isArray(newItem.product_bundle) && (_newItem$product_bund = newItem.product_bundle[_bundleIdx]) !== null && _newItem$product_bund !== void 0 && _newItem$product_bund._promotion) {
|
|
1309
|
+
newItem.product_bundle[_bundleIdx]._promotion.giftInfo = giftInfoData;
|
|
1310
|
+
} else if (metadata._promotion) {
|
|
1311
|
+
metadata._promotion.giftInfo = giftInfoData;
|
|
1312
|
+
}
|
|
1313
|
+
strategyGiftInfoOwner.set(_priced.strategyId, getOrderProductUid(newItem));
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// 记录原商品 uid(用于排序与未满足匹配)
|
|
1318
|
+
newItem._sortIndex = originalIndex;
|
|
1319
|
+
newItem._sortSubIndex = _priced.inPromotion ? 0 : 1;
|
|
1320
|
+
newItem._originalProductUid = getOrderProductUid(originalItem);
|
|
1321
|
+
processedProducts.push(newItem);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
// 7. 赠品/编辑商品原样拼回;同时同步赠品的 sourceProductIds / sourceProductId
|
|
1325
|
+
} catch (err) {
|
|
1326
|
+
_iterator20.e(err);
|
|
1327
|
+
} finally {
|
|
1328
|
+
_iterator20.f();
|
|
1329
|
+
}
|
|
1330
|
+
for (var _i2 = 0, _existingGiftsWithInd = existingGiftsWithIndex; _i2 < _existingGiftsWithInd.length; _i2++) {
|
|
1331
|
+
var _getGiftInfo3;
|
|
1332
|
+
var _existingGiftsWithInd2 = _existingGiftsWithInd[_i2],
|
|
1333
|
+
_item2 = _existingGiftsWithInd2.item,
|
|
1334
|
+
_originalListIndex = _existingGiftsWithInd2.originalListIndex;
|
|
1335
|
+
var next = _item2;
|
|
1336
|
+
next._sortIndex = _originalListIndex;
|
|
1337
|
+
next._sortSubIndex = 0;
|
|
1338
|
+
var strategyId = (_getGiftInfo3 = getGiftInfo(next)) === null || _getGiftInfo3 === void 0 ? void 0 : _getGiftInfo3.strategyId;
|
|
1339
|
+
if (strategyId) {
|
|
1340
|
+
var _next$metadata, _next$metadata2;
|
|
1341
|
+
var latest = strategyGiftInfoMap.get(strategyId);
|
|
1342
|
+
var owner = strategyGiftInfoOwner.get(strategyId);
|
|
1343
|
+
if (latest && (_next$metadata = next.metadata) !== null && _next$metadata !== void 0 && _next$metadata._giftInfo) {
|
|
1344
|
+
next.metadata._giftInfo.sourceProductIds = latest.sourceProductIds;
|
|
1345
|
+
}
|
|
1346
|
+
if (owner && (_next$metadata2 = next.metadata) !== null && _next$metadata2 !== void 0 && _next$metadata2._giftInfo) {
|
|
1347
|
+
next.metadata._giftInfo.sourceProductId = owner;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
processedProducts.push(next);
|
|
1351
|
+
}
|
|
1352
|
+
for (var _i3 = 0, _editProductsWithInde = editProductsWithIndex; _i3 < _editProductsWithInde.length; _i3++) {
|
|
1353
|
+
var _editProductsWithInde2 = _editProductsWithInde[_i3],
|
|
1354
|
+
_item3 = _editProductsWithInde2.item,
|
|
1355
|
+
_originalListIndex2 = _editProductsWithInde2.originalListIndex;
|
|
1356
|
+
var _next = _item3;
|
|
1357
|
+
_next._sortIndex = _originalListIndex2;
|
|
1358
|
+
_next._sortSubIndex = 0;
|
|
1359
|
+
processedProducts.push(_next);
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
// 8. 排序回原顺序,参与促销的拆分行排在前
|
|
1363
|
+
processedProducts.sort(function (a, b) {
|
|
1364
|
+
if (a._sortIndex !== b._sortIndex) return a._sortIndex - b._sortIndex;
|
|
1365
|
+
return a._sortSubIndex - b._sortSubIndex;
|
|
1366
|
+
});
|
|
1367
|
+
|
|
1368
|
+
// 8.1 同款参与促销行:先去重(买赠+满减并存)再合并 num
|
|
1369
|
+
var dedupedPromotionLines = dedupePromotionProcessedLines(processedProducts);
|
|
1370
|
+
processedProducts.splice.apply(processedProducts, [0, processedProducts.length].concat(_toConsumableArray(dedupedPromotionLines)));
|
|
1371
|
+
var mergedPromotionLines = mergeIdenticalPromotionCartLines(processedProducts);
|
|
1372
|
+
processedProducts.splice.apply(processedProducts, [0, processedProducts.length].concat(_toConsumableArray(mergedPromotionLines)));
|
|
1373
|
+
var splitPromoLines = splitXItemsPromoLinesByGroup(processedProducts, strategyActionMap);
|
|
1374
|
+
processedProducts.splice.apply(processedProducts, [0, processedProducts.length].concat(_toConsumableArray(splitPromoLines)));
|
|
1375
|
+
|
|
1376
|
+
// 9. 给「有适用策略但未参与促销」的主商品打 inPromotion:false
|
|
1377
|
+
var _loop3 = function _loop3() {
|
|
1378
|
+
var _product$_originalPro2;
|
|
1379
|
+
var product = _processedProducts[_i4];
|
|
1380
|
+
var metadata = product.metadata || {};
|
|
1381
|
+
if (metadata._promotion) return 0; // continue
|
|
1382
|
+
if (getGiftInfo(product)) return 0; // continue
|
|
1383
|
+
var lookupUid = String((_product$_originalPro2 = product._originalProductUid) !== null && _product$_originalPro2 !== void 0 ? _product$_originalPro2 : getOrderProductUid(product));
|
|
1384
|
+
var originalIndex = mainProducts.findIndex(function (item) {
|
|
1385
|
+
return getOrderProductUid(item) === lookupUid;
|
|
1386
|
+
});
|
|
1387
|
+
if (originalIndex === -1) return 0; // continue
|
|
1388
|
+
var strategyData = applicableStrategiesResult[originalIndex];
|
|
1389
|
+
if (!strategyData || !strategyData.hasApplicableStrategy) return 0; // continue
|
|
1390
|
+
var first = strategyData.applicableStrategies[0];
|
|
1391
|
+
if (!first) return 0; // continue
|
|
1392
|
+
var originalPrice = getOrderProductOriginalPriceForPromotion(mainProducts[originalIndex]);
|
|
1393
|
+
metadata._promotion = {
|
|
1394
|
+
strategyId: first.strategyId,
|
|
1395
|
+
strategyMetadata: first.strategyMetadata,
|
|
1396
|
+
inPromotion: false,
|
|
1397
|
+
originalPrice: originalPrice,
|
|
1398
|
+
finalPrice: originalPrice
|
|
1399
|
+
};
|
|
1400
|
+
product.metadata = metadata;
|
|
1401
|
+
},
|
|
1402
|
+
_ret2;
|
|
1403
|
+
for (var _i4 = 0, _processedProducts = processedProducts; _i4 < _processedProducts.length; _i4++) {
|
|
1404
|
+
_ret2 = _loop3();
|
|
1405
|
+
if (_ret2 === 0) continue;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
// 10. 赠品操作(在更新 lastEvaluatedGiftCount 前做对比)
|
|
1409
|
+
var giftActions = calculateGiftActions(extendedGifts, existingGifts);
|
|
1410
|
+
|
|
1411
|
+
// 10.1 更新 lastEvaluatedGiftCount,便于下次评估时判别「策略已变」
|
|
1412
|
+
var _iterator21 = _createForOfIteratorHelper(existingGifts),
|
|
1413
|
+
_step21;
|
|
1414
|
+
try {
|
|
1415
|
+
for (_iterator21.s(); !(_step21 = _iterator21.n()).done;) {
|
|
1416
|
+
var _getGiftInfo4, _metadata;
|
|
1417
|
+
var _gift3 = _step21.value;
|
|
1418
|
+
var _strategyId3 = (_getGiftInfo4 = getGiftInfo(_gift3)) === null || _getGiftInfo4 === void 0 ? void 0 : _getGiftInfo4.strategyId;
|
|
1419
|
+
if (!_strategyId3) continue;
|
|
1420
|
+
var _latest = strategyGiftInfoMap.get(_strategyId3);
|
|
1421
|
+
if (_latest && (_metadata = _gift3.metadata) !== null && _metadata !== void 0 && _metadata._giftInfo) {
|
|
1422
|
+
_gift3.metadata._giftInfo.lastEvaluatedGiftCount = _latest.giftCount;
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
// 11. 未满足促销
|
|
1427
|
+
} catch (err) {
|
|
1428
|
+
_iterator21.e(err);
|
|
1429
|
+
} finally {
|
|
1430
|
+
_iterator21.f();
|
|
1431
|
+
}
|
|
1432
|
+
var unfulfilledPromotions = calculateUnfulfilledPromotions(processedProducts, applicableStrategiesResult, mainProducts);
|
|
1433
|
+
|
|
1434
|
+
// 12. 清理排序辅助字段
|
|
1435
|
+
for (var _i5 = 0, _processedProducts2 = processedProducts; _i5 < _processedProducts2.length; _i5++) {
|
|
1436
|
+
var product = _processedProducts2[_i5];
|
|
1437
|
+
delete product._sortIndex;
|
|
1438
|
+
delete product._sortSubIndex;
|
|
1439
|
+
delete product._originalProductUid;
|
|
1440
|
+
delete product._sourceCartNum;
|
|
1441
|
+
delete product._wasInPromotionBeforeConsolidate;
|
|
1442
|
+
}
|
|
1443
|
+
return {
|
|
1444
|
+
products: processedProducts,
|
|
1445
|
+
totalDiscount: result.totalDiscount,
|
|
1446
|
+
gifts: extendedGifts,
|
|
1447
|
+
giftActions: giftActions,
|
|
1448
|
+
unfulfilledPromotions: unfulfilledPromotions
|
|
1449
|
+
};
|
|
1450
|
+
}
|