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