@pisell/pisellos 0.0.569 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.js +10 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -3
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +7 -5
- package/dist/model/strategy/adapter/walletPass/example.js +26 -3
- package/dist/model/strategy/adapter/walletPass/index.js +5 -5
- package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -3
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -26
- package/dist/model/strategy/adapter/walletPass/utils.js +17 -92
- package/dist/model/strategy/strategy-example.js +19 -5
- package/dist/modules/BaseModule.d.ts +1 -1
- package/dist/modules/BaseModule.js +8 -10
- package/dist/modules/Cart/index.js +3 -0
- package/dist/modules/Cart/utils/cartProduct.js +1 -0
- package/dist/modules/Cart/utils/cartResource.js +0 -2
- package/dist/modules/Cart/utils/changePrice.js +9 -16
- package/dist/modules/Date/index.js +5 -1
- package/dist/modules/Discount/index.d.ts +0 -1
- package/dist/modules/Discount/index.js +7 -22
- package/dist/modules/Discount/types.d.ts +0 -1
- package/dist/modules/OpenData/index.js +2 -0
- package/dist/modules/Order/index.js +70 -40
- package/dist/modules/Payment/index.js +162 -97
- package/dist/modules/Payment/types.d.ts +4 -8
- package/dist/modules/Payment/walletpass.d.ts +0 -2
- package/dist/modules/Payment/walletpass.js +5 -4
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +3 -12
- package/dist/modules/ProductList/types.d.ts +0 -1
- package/dist/modules/Rules/index.js +126 -427
- package/dist/modules/SalesSummary/utils.js +1 -2
- package/dist/modules/Schedule/getDateIsInSchedule.js +0 -5
- package/dist/modules/Schedule/index.js +1 -0
- package/dist/modules/Schedule/utils.js +1 -0
- package/dist/modules/Step/index.js +1 -0
- package/dist/modules/Summary/utils.js +22 -43
- package/dist/plugins/request.js +4 -1
- package/dist/plugins/window.js +6 -2
- package/dist/server/index.js +129 -97
- package/dist/server/modules/menu/index.js +41 -32
- package/dist/server/modules/order/index.js +4 -2
- package/dist/server/modules/products/index.js +42 -24
- package/dist/server/modules/quotation/index.js +38 -29
- package/dist/server/modules/resource/index.js +4 -3
- package/dist/server/modules/schedule/index.js +35 -27
- package/dist/server/utils/product.js +1 -0
- package/dist/solution/BaseSales/index.js +41 -38
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +60 -11
- package/dist/solution/BookingByStep/utils/capacity.js +11 -1
- package/dist/solution/BookingByStep/utils/resources.js +3 -1
- package/dist/solution/BookingByStep/utils/timeslots.js +43 -2
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.js +2 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +7 -6
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +31 -25
- package/dist/solution/BookingTicket/utils/scan/index.js +10 -6
- package/dist/solution/BuyTickets/index.js +12 -9
- package/dist/solution/Checkout/index.js +252 -177
- package/dist/solution/Checkout/utils/index.js +16 -4
- package/dist/solution/RegisterAndLogin/index.js +76 -30
- package/dist/solution/ScanOrder/index.js +60 -50
- package/dist/solution/ShopDiscount/index.js +14 -15
- package/dist/solution/ShopDiscount/types.d.ts +4 -5
- package/dist/solution/ShopDiscount/utils.d.ts +0 -9
- package/dist/solution/ShopDiscount/utils.js +0 -9
- package/dist/solution/VenueBooking/index.d.ts +3 -31
- package/dist/solution/VenueBooking/index.js +496 -651
- package/dist/solution/VenueBooking/types.d.ts +1 -3
- package/dist/solution/VenueBooking/types.js +0 -1
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/dist/solution/VenueBooking/utils/dateSummary.js +25 -12
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
- package/dist/solution/VenueBooking/utils/timeSlot.js +4 -9
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/task.js +18 -15
- package/dist/utils/watch.js +1 -0
- package/lib/apis/picoding.js +0 -2
- package/lib/core/index.js +132 -130
- package/lib/effects/index.js +57 -46
- package/lib/index.d.ts +0 -1
- package/lib/index.js +50 -92
- package/lib/model/index.js +21 -14
- package/lib/model/strategy/adapter/dataVariant/adapter.js +50 -38
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +236 -162
- package/lib/model/strategy/adapter/dataVariant/examples.js +237 -229
- package/lib/model/strategy/adapter/dataVariant/index.js +34 -39
- package/lib/model/strategy/adapter/dataVariant/type.js +28 -57
- package/lib/model/strategy/adapter/index.js +64 -100
- package/lib/model/strategy/adapter/itemRule/adapter.js +144 -156
- package/lib/model/strategy/adapter/itemRule/evaluator.js +48 -36
- package/lib/model/strategy/adapter/itemRule/examples.js +225 -295
- package/lib/model/strategy/adapter/itemRule/index.js +57 -83
- package/lib/model/strategy/adapter/itemRule/type.js +36 -97
- package/lib/model/strategy/adapter/promotion/adapter.js +63 -84
- package/lib/model/strategy/adapter/promotion/evaluator.js +231 -381
- package/lib/model/strategy/adapter/promotion/examples.js +159 -139
- package/lib/model/strategy/adapter/promotion/index.js +49 -1
- package/lib/model/strategy/adapter/promotion/type.js +35 -199
- package/lib/model/strategy/adapter/type.js +16 -4
- package/lib/model/strategy/adapter/walletPass/evaluator.js +152 -180
- package/lib/model/strategy/adapter/walletPass/example.js +190 -217
- package/lib/model/strategy/adapter/walletPass/index.js +51 -75
- package/lib/model/strategy/adapter/walletPass/locales.js +58 -36
- package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -3
- package/lib/model/strategy/adapter/walletPass/type.js +16 -4
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -26
- package/lib/model/strategy/adapter/walletPass/utils.js +383 -678
- package/lib/model/strategy/engine.js +168 -270
- package/lib/model/strategy/index.js +34 -49
- package/lib/model/strategy/strategy-example.js +239 -243
- package/lib/model/strategy/type.js +40 -100
- package/lib/modules/Account/index.js +53 -39
- package/lib/modules/Account/types.js +33 -20
- package/lib/modules/AccountList/index.js +154 -116
- package/lib/modules/AccountList/types.js +31 -30
- package/lib/modules/AccountList/utils.js +30 -18
- package/lib/modules/BaseModule.d.ts +1 -1
- package/lib/modules/BaseModule.js +46 -25
- package/lib/modules/BookingContext/index.js +136 -158
- package/lib/modules/BookingContext/types.js +32 -46
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +143 -131
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +82 -75
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +150 -170
- package/lib/modules/BookingContext/utils/flexible.js +55 -38
- package/lib/modules/BookingContext/utils/formatResourceList.js +34 -19
- package/lib/modules/BookingContext/utils/index.js +41 -124
- package/lib/modules/BookingContext/utils/noResource.js +70 -58
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +41 -14
- package/lib/modules/BookingContext/utils/productExtend.js +155 -202
- package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
- package/lib/modules/BookingContext/utils/resourceSelection.js +41 -19
- package/lib/modules/BookingContext/utils/resources.js +167 -209
- package/lib/modules/BookingContext/utils/serviceTimes.js +116 -115
- package/lib/modules/BookingContext/utils/timeSlices.js +80 -70
- package/lib/modules/Cart/index.js +124 -170
- package/lib/modules/Cart/types.js +51 -46
- package/lib/modules/Cart/utils/cartAccount.js +39 -40
- package/lib/modules/Cart/utils/cartDate.js +61 -56
- package/lib/modules/Cart/utils/cartDiscount.js +33 -28
- package/lib/modules/Cart/utils/cartNote.js +32 -27
- package/lib/modules/Cart/utils/cartProduct.js +251 -321
- package/lib/modules/Cart/utils/cartRelationForms.js +35 -29
- package/lib/modules/Cart/utils/cartResource.js +78 -72
- package/lib/modules/Cart/utils/changePrice.js +50 -28
- package/lib/modules/Cart/utils/index.js +48 -106
- package/lib/modules/Customer/constants.js +34 -13
- package/lib/modules/Customer/index.js +169 -232
- package/lib/modules/Customer/types.js +35 -38
- package/lib/modules/Date/index.js +115 -116
- package/lib/modules/Date/types.js +28 -16
- package/lib/modules/Date/utils.js +123 -174
- package/lib/modules/Discount/index.d.ts +0 -1
- package/lib/modules/Discount/index.js +128 -130
- package/lib/modules/Discount/types.d.ts +0 -1
- package/lib/modules/Discount/types.js +31 -9
- package/lib/modules/Guests/index.js +56 -30
- package/lib/modules/Guests/types.js +33 -23
- package/lib/modules/Holder/index.js +189 -209
- package/lib/modules/Holder/types.js +16 -4
- package/lib/modules/Holder/utils.js +49 -20
- package/lib/modules/OpenData/index.js +76 -69
- package/lib/modules/OpenData/types.js +16 -4
- package/lib/modules/OpenData/utils.js +78 -44
- package/lib/modules/Order/index.js +1909 -1572
- package/lib/modules/Order/types.js +35 -78
- package/lib/modules/Order/utils/bundleDiscountHydration.js +74 -41
- package/lib/modules/Order/utils/manualProductDiscount.js +123 -124
- package/lib/modules/Order/utils/orderCollectionIdentity.js +210 -148
- package/lib/modules/Order/utils.js +634 -799
- package/lib/modules/Payment/cash.js +33 -20
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +76 -145
- package/lib/modules/Payment/eftpos.js +30 -16
- package/lib/modules/Payment/index.js +378 -518
- package/lib/modules/Payment/mx51.js +0 -1
- package/lib/modules/Payment/types.d.ts +4 -8
- package/lib/modules/Payment/types.js +107 -216
- package/lib/modules/Payment/utils.js +48 -51
- package/lib/modules/Payment/walletpass.d.ts +0 -2
- package/lib/modules/Payment/walletpass.js +211 -226
- package/lib/modules/Product/index.js +46 -51
- package/lib/modules/Product/types.js +16 -4
- package/lib/modules/Product/utils.js +33 -32
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +117 -117
- package/lib/modules/ProductList/types.d.ts +0 -1
- package/lib/modules/ProductList/types.js +31 -9
- package/lib/modules/Quotation/index.js +100 -66
- package/lib/modules/Quotation/types.js +16 -4
- package/lib/modules/Resource/index.js +59 -27
- package/lib/modules/Resource/types.js +32 -22
- package/lib/modules/Resource/utils.js +38 -30
- package/lib/modules/ResourcePlanner/index.js +61 -60
- package/lib/modules/ResourcePlanner/planner.js +384 -346
- package/lib/modules/ResourcePlanner/types.js +16 -4
- package/lib/modules/Rules/index.js +903 -1475
- package/lib/modules/Rules/types.js +40 -17
- package/lib/modules/SalesSummary/index.js +90 -85
- package/lib/modules/SalesSummary/types.js +16 -4
- package/lib/modules/SalesSummary/utils.js +427 -351
- package/lib/modules/ScanOrderLogger/index.js +79 -59
- package/lib/modules/ScanOrderLogger/providers/feishu.js +78 -54
- package/lib/modules/ScanOrderLogger/providers/grafana.js +36 -13
- package/lib/modules/ScanOrderLogger/types.js +16 -4
- package/lib/modules/Schedule/getDateIsInSchedule.js +163 -339
- package/lib/modules/Schedule/index.js +114 -100
- package/lib/modules/Schedule/type.js +16 -4
- package/lib/modules/Schedule/types.js +16 -4
- package/lib/modules/Schedule/utils.js +291 -433
- package/lib/modules/Step/index.js +52 -40
- package/lib/modules/Step/tyeps.js +16 -4
- package/lib/modules/Summary/index.js +71 -66
- package/lib/modules/Summary/types.js +16 -4
- package/lib/modules/Summary/utils.js +418 -791
- package/lib/modules/SurchargeList/index.js +60 -46
- package/lib/modules/SurchargeList/types.js +16 -4
- package/lib/modules/index.js +63 -245
- package/lib/plugins/app.js +16 -4
- package/lib/plugins/index.js +25 -36
- package/lib/plugins/request.js +126 -137
- package/lib/plugins/shopStore.js +16 -4
- package/lib/plugins/user.js +16 -4
- package/lib/plugins/window.js +179 -171
- package/lib/server/index.js +2337 -2675
- package/lib/server/modules/floor-plan/index.js +123 -102
- package/lib/server/modules/floor-plan/types.js +30 -15
- package/lib/server/modules/index.js +68 -106
- package/lib/server/modules/menu/index.js +122 -146
- package/lib/server/modules/menu/types.js +31 -18
- package/lib/server/modules/order/index.js +642 -567
- package/lib/server/modules/order/types.js +32 -117
- package/lib/server/modules/order/utils/filterBookings.js +194 -219
- package/lib/server/modules/order/utils/filterOrders.js +92 -118
- package/lib/server/modules/payment/index.js +83 -59
- package/lib/server/modules/payment/types.js +16 -4
- package/lib/server/modules/products/index.js +459 -575
- package/lib/server/modules/products/types.js +34 -44
- package/lib/server/modules/quotation/index.js +172 -137
- package/lib/server/modules/quotation/types.js +31 -21
- package/lib/server/modules/resource/index.js +184 -213
- package/lib/server/modules/resource/types.js +33 -42
- package/lib/server/modules/schedule/index.js +123 -135
- package/lib/server/modules/schedule/types.js +21 -14
- package/lib/server/modules/schedule/utils.js +163 -334
- package/lib/server/types.js +16 -4
- package/lib/server/utils/index.js +23 -25
- package/lib/server/utils/product.js +139 -196
- package/lib/server/utils/schedule.js +41 -34
- package/lib/server/utils/small-ticket.js +456 -478
- package/lib/server/utils/time.js +49 -40
- package/lib/solution/BaseSales/index.js +1016 -850
- package/lib/solution/BaseSales/types.js +37 -41
- package/lib/solution/BaseSales/utils/cartPromotion.js +460 -611
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +105 -85
- package/lib/solution/BaseSales/utils/quotationPrice.js +114 -56
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +143 -102
- package/lib/solution/BaseSales/utils.js +140 -155
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +1340 -1530
- package/lib/solution/BookingByStep/types.js +99 -40
- package/lib/solution/BookingByStep/utils/capacity.js +160 -192
- package/lib/solution/BookingByStep/utils/products.js +52 -42
- package/lib/solution/BookingByStep/utils/resources.js +330 -527
- package/lib/solution/BookingByStep/utils/stock.js +44 -65
- package/lib/solution/BookingByStep/utils/timeslots.js +131 -129
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +459 -543
- package/lib/solution/BookingTicket/types.js +77 -99
- package/lib/solution/BookingTicket/utils/addProductDecision.js +184 -219
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +89 -58
- package/lib/solution/BookingTicket/utils/bookingStatus.js +78 -107
- package/lib/solution/BookingTicket/utils/cartView.js +94 -110
- package/lib/solution/BookingTicket/utils/exampleData.js +0 -185
- package/lib/solution/BookingTicket/utils/orderCustomer.js +41 -18
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +86 -219
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +93 -144
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +91 -79
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +41 -54
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +81 -84
- package/lib/solution/BookingTicket/utils/scan/index.js +104 -98
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +43 -90
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +64 -52
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +58 -56
- package/lib/solution/BuyTickets/index.js +70 -67
- package/lib/solution/BuyTickets/types.js +38 -22
- package/lib/solution/Checkout/index.js +1158 -1451
- package/lib/solution/Checkout/types.js +61 -91
- package/lib/solution/Checkout/utils/index.js +156 -228
- package/lib/solution/PlaceOrder/index.js +0 -55
- package/lib/solution/RegisterAndLogin/config.js +460 -493
- package/lib/solution/RegisterAndLogin/index.js +630 -633
- package/lib/solution/RegisterAndLogin/types.js +76 -189
- package/lib/solution/RegisterAndLogin/utils.js +125 -183
- package/lib/solution/Sales/index.js +320 -317
- package/lib/solution/Sales/types.js +33 -27
- package/lib/solution/ScanOrder/index.js +862 -831
- package/lib/solution/ScanOrder/types.js +34 -33
- package/lib/solution/ScanOrder/utils.js +371 -406
- package/lib/solution/ShopDiscount/index.js +233 -235
- package/lib/solution/ShopDiscount/types.d.ts +4 -5
- package/lib/solution/ShopDiscount/types.js +37 -15
- package/lib/solution/ShopDiscount/utils.d.ts +0 -9
- package/lib/solution/ShopDiscount/utils.js +172 -309
- package/lib/solution/UnifiedBookingSales/index.js +405 -379
- package/lib/solution/UnifiedBookingSales/types.js +31 -12
- package/lib/solution/VenueBooking/index.d.ts +3 -31
- package/lib/solution/VenueBooking/index.js +916 -967
- package/lib/solution/VenueBooking/types.d.ts +1 -3
- package/lib/solution/VenueBooking/types.js +39 -20
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/lib/solution/VenueBooking/utils/dateSummary.js +62 -25
- package/lib/solution/VenueBooking/utils/resource.js +54 -31
- package/lib/solution/VenueBooking/utils/slotMerge.js +107 -94
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -2
- package/lib/solution/VenueBooking/utils/timeSlot.js +133 -138
- package/lib/solution/VenueBooking/utils.js +67 -130
- package/lib/solution/index.js +41 -124
- package/lib/store/createStore.js +29 -32
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.js +16 -4
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +47 -81
- package/package.json +2 -4
- package/dist/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
- package/dist/solution/VenueBooking/utils/smartPricing.js +0 -233
- package/lib/solution/VenueBooking/utils/smartPricing.d.ts +0 -70
- package/lib/solution/VenueBooking/utils/smartPricing.js +0 -192
|
@@ -1,97 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/solution/ShopDiscount/utils.ts
|
|
30
|
+
var utils_exports = {};
|
|
31
|
+
__export(utils_exports, {
|
|
32
|
+
calculateOrderLevelDiscountAllocation: () => calculateOrderLevelDiscountAllocation,
|
|
33
|
+
filterDiscountListByBookingTime: () => filterDiscountListByBookingTime,
|
|
34
|
+
getDateIsInSchedule: () => getDateIsInSchedule,
|
|
35
|
+
getDiscountAmount: () => getDiscountAmount,
|
|
36
|
+
getDiscountListAmount: () => getDiscountListAmount,
|
|
37
|
+
getDiscountListAmountTotal: () => getDiscountListAmountTotal,
|
|
38
|
+
isAllNormalProduct: () => isAllNormalProduct,
|
|
39
|
+
isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
|
|
40
|
+
isOrderLevelFixedAmountDiscount: () => isOrderLevelFixedAmountDiscount,
|
|
41
|
+
uniqueById: () => uniqueById
|
|
5
42
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
return arr.filter(item => !seen.has(item[key]) && seen.add(item[key]));
|
|
43
|
+
module.exports = __toCommonJS(utils_exports);
|
|
44
|
+
var import_decimal = __toESM(require("decimal.js"));
|
|
45
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
46
|
+
var uniqueById = (arr, key = "id") => {
|
|
47
|
+
const seen = /* @__PURE__ */ new Set();
|
|
48
|
+
return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
|
|
13
49
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const isNormalProductByDurationSchedule = item => {
|
|
18
|
-
return !item?.duration && !item?.schedules?.length && !item?.['schedule.ids']?.length;
|
|
50
|
+
var isNormalProductByDurationSchedule = (item) => {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
return !(item == null ? void 0 : item.duration) && !((_a = item == null ? void 0 : item.schedules) == null ? void 0 : _a.length) && !((_b = item == null ? void 0 : item["schedule.ids"]) == null ? void 0 : _b.length);
|
|
19
53
|
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
exports.isNormalProductByDurationSchedule = isNormalProductByDurationSchedule;
|
|
23
|
-
const isAllNormalProduct = items => {
|
|
24
|
-
return items.every(item => isNormalProductByDurationSchedule(item));
|
|
54
|
+
var isAllNormalProduct = (items) => {
|
|
55
|
+
return items.every((item) => isNormalProductByDurationSchedule(item));
|
|
25
56
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
31
|
-
* @param discount
|
|
32
|
-
* @param total
|
|
33
|
-
* @param price
|
|
34
|
-
* @returns
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* 获取折扣金额 基于折扣卡类型计算
|
|
38
|
-
* 商品券:直接返回商品价格
|
|
39
|
-
* 折扣卡:根据折扣卡类型计算 固定金额:直接返回折扣卡金额 百分比:根据折扣卡金额计算
|
|
40
|
-
* @param discount
|
|
41
|
-
* @param total
|
|
42
|
-
* @param price
|
|
43
|
-
* @returns
|
|
44
|
-
*/
|
|
45
|
-
exports.isAllNormalProduct = isAllNormalProduct;
|
|
46
|
-
const getDiscountAmount = (discount, total, price) => {
|
|
47
|
-
// 商品券
|
|
48
|
-
if (discount.tag === 'good_pass') {
|
|
49
|
-
return new _decimal.default(price).minus(new _decimal.default(price || 0)).toNumber();
|
|
57
|
+
var getDiscountAmount = (discount, total, price) => {
|
|
58
|
+
var _a;
|
|
59
|
+
if (discount.tag === "good_pass") {
|
|
60
|
+
return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
|
|
50
61
|
}
|
|
51
|
-
|
|
52
|
-
// 判断是否是固定金额
|
|
53
|
-
const isFixedAmount = discount?.metadata?.discount_card_type === 'fixed_amount';
|
|
54
|
-
|
|
55
|
-
// 固定金额 小于0时返回0
|
|
62
|
+
const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
|
|
56
63
|
if (isFixedAmount) {
|
|
57
|
-
return Math.max(new
|
|
64
|
+
return Math.max(new import_decimal.default(price).minus(new import_decimal.default((discount.amount ?? discount.par_value) || 0)).toNumber(), 0);
|
|
58
65
|
}
|
|
59
|
-
|
|
60
|
-
// 百分比:根据折扣卡金额计算
|
|
61
|
-
return new _decimal.default(100).minus(discount.par_value || 0).div(100).mul(new _decimal.default(price)).toNumber();
|
|
66
|
+
return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
|
|
62
67
|
};
|
|
63
|
-
|
|
64
|
-
const getDiscountListAmountTotal = discount => {
|
|
68
|
+
var getDiscountListAmountTotal = (discount) => {
|
|
65
69
|
return discount.reduce((acc, cur) => {
|
|
66
|
-
return new
|
|
67
|
-
}, new
|
|
70
|
+
return new import_decimal.default(acc).plus(new import_decimal.default(cur.num || 1).mul(new import_decimal.default(cur.amount || 0))).toNumber();
|
|
71
|
+
}, new import_decimal.default(0));
|
|
68
72
|
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 获取折扣金额 计算每个折扣的金额
|
|
72
|
-
* @param discount
|
|
73
|
-
* @returns
|
|
74
|
-
*/
|
|
75
|
-
exports.getDiscountListAmountTotal = getDiscountListAmountTotal;
|
|
76
|
-
const getDiscountListAmount = discount => {
|
|
73
|
+
var getDiscountListAmount = (discount) => {
|
|
77
74
|
return discount.reduce((acc, cur) => {
|
|
78
|
-
return new
|
|
79
|
-
}, new
|
|
75
|
+
return new import_decimal.default(acc).plus(new import_decimal.default(cur.amount || 0)).toNumber();
|
|
76
|
+
}, new import_decimal.default(0));
|
|
80
77
|
};
|
|
81
|
-
|
|
82
|
-
// 日程项接口定义
|
|
83
|
-
exports.getDiscountListAmount = getDiscountListAmount;
|
|
84
|
-
// 获取时间是否在日程范围内
|
|
85
|
-
const getDateIsInSchedule = (dateTime, scheduleList) => {
|
|
78
|
+
var getDateIsInSchedule = (dateTime, scheduleList) => {
|
|
86
79
|
if (!dateTime || !scheduleList || scheduleList.length === 0) {
|
|
87
80
|
return false;
|
|
88
81
|
}
|
|
89
|
-
const targetDate = (0,
|
|
82
|
+
const targetDate = (0, import_dayjs.default)(dateTime);
|
|
90
83
|
if (!targetDate.isValid()) {
|
|
91
84
|
return false;
|
|
92
85
|
}
|
|
93
|
-
|
|
94
|
-
// 遍历所有日程项
|
|
95
86
|
for (const schedule of scheduleList) {
|
|
96
87
|
if (isTimeInScheduleItem(dateTime, schedule)) {
|
|
97
88
|
return true;
|
|
@@ -99,422 +90,284 @@ const getDateIsInSchedule = (dateTime, scheduleList) => {
|
|
|
99
90
|
}
|
|
100
91
|
return false;
|
|
101
92
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
const targetDate = (0, _dayjs.default)(dateTime);
|
|
107
|
-
const targetDateString = dateTime.split(' ')[0]; // YYYY-MM-DD
|
|
108
|
-
const targetTimeString = dateTime.split(' ')[1] || '00:00:00'; // HH:mm:ss
|
|
109
|
-
|
|
93
|
+
var isTimeInScheduleItem = (dateTime, schedule) => {
|
|
94
|
+
const targetDate = (0, import_dayjs.default)(dateTime);
|
|
95
|
+
const targetDateString = dateTime.split(" ")[0];
|
|
96
|
+
const targetTimeString = dateTime.split(" ")[1] || "00:00:00";
|
|
110
97
|
switch (schedule.type) {
|
|
111
|
-
case
|
|
98
|
+
case "standard":
|
|
112
99
|
return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
113
|
-
case
|
|
100
|
+
case "time-slots":
|
|
114
101
|
return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
115
|
-
case
|
|
102
|
+
case "designation":
|
|
116
103
|
return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
117
104
|
default:
|
|
118
105
|
return false;
|
|
119
106
|
}
|
|
120
107
|
};
|
|
121
|
-
|
|
122
|
-
// 处理标准类型日程
|
|
123
|
-
const isInStandardSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
108
|
+
var isInStandardSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
124
109
|
if (!schedule.start_time || !schedule.end_time) {
|
|
125
110
|
return false;
|
|
126
111
|
}
|
|
127
|
-
const startDate = (0,
|
|
128
|
-
const endDate = (0,
|
|
129
|
-
|
|
130
|
-
// 先检查是否在基础时间范围内(不考虑重复)
|
|
112
|
+
const startDate = (0, import_dayjs.default)(schedule.start_time);
|
|
113
|
+
const endDate = (0, import_dayjs.default)(schedule.end_time);
|
|
131
114
|
const isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate);
|
|
132
|
-
if (schedule.repeat_type ===
|
|
115
|
+
if (schedule.repeat_type === "none") {
|
|
133
116
|
return isInBasicRange;
|
|
134
117
|
}
|
|
135
|
-
|
|
136
|
-
// 处理重复日程
|
|
137
118
|
return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
|
|
138
119
|
};
|
|
139
|
-
|
|
140
|
-
// 处理时间段类型日程
|
|
141
|
-
const isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
120
|
+
var isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
142
121
|
if (!schedule.start_time) {
|
|
143
122
|
return false;
|
|
144
123
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (schedule.repeat_type === 'none') {
|
|
148
|
-
const scheduleDate = schedule.start_time.split(' ')[0];
|
|
149
|
-
|
|
150
|
-
// 检查日期是否匹配
|
|
124
|
+
if (schedule.repeat_type === "none") {
|
|
125
|
+
const scheduleDate = schedule.start_time.split(" ")[0];
|
|
151
126
|
if (targetDateString !== scheduleDate) {
|
|
152
127
|
return false;
|
|
153
128
|
}
|
|
154
|
-
|
|
155
|
-
// 检查是否在任一时间段内
|
|
156
129
|
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
157
130
|
}
|
|
158
|
-
|
|
159
|
-
// 处理重复日程
|
|
160
131
|
return isInTimeSlotsRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule);
|
|
161
132
|
};
|
|
162
|
-
|
|
163
|
-
// 处理指定类型日程
|
|
164
|
-
const isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
133
|
+
var isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
165
134
|
if (!schedule.designation) {
|
|
166
135
|
return false;
|
|
167
136
|
}
|
|
168
137
|
for (const designation of schedule.designation) {
|
|
169
138
|
const startDateTime = `${designation.start_date} ${designation.start_time}:00`;
|
|
170
139
|
const endDateTime = `${designation.end_date} ${designation.end_time}:00`;
|
|
171
|
-
const startDate = (0,
|
|
172
|
-
const endDate = (0,
|
|
140
|
+
const startDate = (0, import_dayjs.default)(startDateTime);
|
|
141
|
+
const endDate = (0, import_dayjs.default)(endDateTime);
|
|
173
142
|
if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
|
|
174
143
|
return true;
|
|
175
144
|
}
|
|
176
145
|
}
|
|
177
146
|
return false;
|
|
178
147
|
};
|
|
179
|
-
|
|
180
|
-
// 处理重复日程逻辑
|
|
181
|
-
const isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) => {
|
|
148
|
+
var isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) => {
|
|
182
149
|
if (!schedule.repeat_rule) {
|
|
183
150
|
return false;
|
|
184
151
|
}
|
|
185
|
-
const {
|
|
186
|
-
|
|
187
|
-
repeat_type
|
|
188
|
-
} = schedule;
|
|
189
|
-
const targetDateOnly = (0, _dayjs.default)(targetDateString); // 只取日期部分
|
|
190
|
-
|
|
191
|
-
// 首先检查是否在包含日期中(包含日期是额外增加的有效日期)
|
|
152
|
+
const { repeat_rule, repeat_type } = schedule;
|
|
153
|
+
const targetDateOnly = (0, import_dayjs.default)(targetDateString);
|
|
192
154
|
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
193
155
|
for (const includedDate of repeat_rule.included_date) {
|
|
194
|
-
const includeStartDate = (0,
|
|
195
|
-
const includeEndDate = (0,
|
|
196
|
-
if (targetDateOnly.isSameOrAfter(includeStartDate,
|
|
197
|
-
// 在包含日期中,直接返回true,无需检查其他条件
|
|
156
|
+
const includeStartDate = (0, import_dayjs.default)(includedDate.start);
|
|
157
|
+
const includeEndDate = (0, import_dayjs.default)(includedDate.end);
|
|
158
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
|
|
198
159
|
return true;
|
|
199
160
|
}
|
|
200
161
|
}
|
|
201
162
|
}
|
|
202
|
-
|
|
203
|
-
// 检查是否在排除日期中
|
|
204
163
|
for (const excludedDate of repeat_rule.excluded_date) {
|
|
205
|
-
const excludeStartDate = (0,
|
|
206
|
-
const excludeEndDate = (0,
|
|
207
|
-
|
|
208
|
-
if (targetDateOnly.isSameOrAfter(excludeStartDate, 'day') && targetDateOnly.isSameOrBefore(excludeEndDate, 'day')) {
|
|
164
|
+
const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
|
|
165
|
+
const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
|
|
166
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
|
|
209
167
|
return false;
|
|
210
168
|
}
|
|
211
169
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
if (repeat_rule.end.type === 'date' && repeat_rule.end.end_date) {
|
|
215
|
-
const ruleEndDate = (0, _dayjs.default)(repeat_rule.end.end_date);
|
|
170
|
+
if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
|
|
171
|
+
const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
|
|
216
172
|
if (targetDate.isAfter(ruleEndDate)) {
|
|
217
173
|
return false;
|
|
218
174
|
}
|
|
219
175
|
}
|
|
220
|
-
|
|
221
|
-
// 根据重复类型检查
|
|
222
176
|
switch (repeat_type) {
|
|
223
|
-
case
|
|
177
|
+
case "daily":
|
|
224
178
|
return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
225
|
-
case
|
|
179
|
+
case "weekly":
|
|
226
180
|
return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
|
|
227
181
|
default:
|
|
228
182
|
return false;
|
|
229
|
-
// 不支持月和年重复
|
|
230
183
|
}
|
|
231
184
|
};
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
235
|
-
const daysDiff = targetDate.diff(startDate, 'day');
|
|
185
|
+
var isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
186
|
+
const daysDiff = targetDate.diff(startDate, "day");
|
|
236
187
|
if (daysDiff < 0) {
|
|
237
188
|
return false;
|
|
238
189
|
}
|
|
239
|
-
|
|
240
|
-
// 检查频率
|
|
241
190
|
if (daysDiff % repeatRule.frequency !== 0) {
|
|
242
191
|
return false;
|
|
243
192
|
}
|
|
244
|
-
|
|
245
|
-
// 检查时间是否在日程的时间范围内
|
|
246
193
|
const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
247
194
|
const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
248
195
|
const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
249
|
-
|
|
250
|
-
// 每日重复:每天都在相同的时间段内有效
|
|
251
|
-
// 例如:01:00:00 - 16:00:00,每天都是这个时间段
|
|
252
196
|
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
253
197
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
const isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
257
|
-
const targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
258
|
-
|
|
259
|
-
// 检查是否在指定的星期几内
|
|
198
|
+
var isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
|
|
199
|
+
const targetDayOfWeek = targetDate.day();
|
|
260
200
|
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
261
201
|
return false;
|
|
262
202
|
}
|
|
263
|
-
|
|
264
|
-
// 计算周差
|
|
265
|
-
const weeksDiff = targetDate.diff(startDate, 'week');
|
|
203
|
+
const weeksDiff = targetDate.diff(startDate, "week");
|
|
266
204
|
if (weeksDiff < 0) {
|
|
267
205
|
return false;
|
|
268
206
|
}
|
|
269
|
-
|
|
270
|
-
// 检查频率
|
|
271
207
|
if (weeksDiff % repeatRule.frequency !== 0) {
|
|
272
208
|
return false;
|
|
273
209
|
}
|
|
274
|
-
|
|
275
|
-
// 检查时间是否在日程的时间范围内
|
|
276
210
|
const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
|
|
277
211
|
const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
|
|
278
212
|
const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
|
|
279
213
|
return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
|
|
280
214
|
};
|
|
281
|
-
|
|
282
|
-
// 处理 time-slots 类型的重复日程
|
|
283
|
-
const isInTimeSlotsRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
215
|
+
var isInTimeSlotsRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
|
|
284
216
|
if (!schedule.repeat_rule || !schedule.start_time) {
|
|
285
217
|
return false;
|
|
286
218
|
}
|
|
287
|
-
const {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
} = schedule;
|
|
291
|
-
const startDate = (0, _dayjs.default)(schedule.start_time);
|
|
292
|
-
const targetDateOnly = (0, _dayjs.default)(targetDateString);
|
|
293
|
-
|
|
294
|
-
// 检查包含日期
|
|
219
|
+
const { repeat_rule, repeat_type } = schedule;
|
|
220
|
+
const startDate = (0, import_dayjs.default)(schedule.start_time);
|
|
221
|
+
const targetDateOnly = (0, import_dayjs.default)(targetDateString);
|
|
295
222
|
if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
|
|
296
223
|
for (const includedDate of repeat_rule.included_date) {
|
|
297
|
-
const includeStartDate = (0,
|
|
298
|
-
const includeEndDate = (0,
|
|
299
|
-
if (targetDateOnly.isSameOrAfter(includeStartDate,
|
|
300
|
-
// 在包含日期中,检查时间段
|
|
224
|
+
const includeStartDate = (0, import_dayjs.default)(includedDate.start);
|
|
225
|
+
const includeEndDate = (0, import_dayjs.default)(includedDate.end);
|
|
226
|
+
if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
|
|
301
227
|
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
302
228
|
}
|
|
303
229
|
}
|
|
304
230
|
}
|
|
305
|
-
|
|
306
|
-
// 检查排除日期
|
|
307
231
|
for (const excludedDate of repeat_rule.excluded_date) {
|
|
308
|
-
const excludeStartDate = (0,
|
|
309
|
-
const excludeEndDate = (0,
|
|
310
|
-
if (targetDateOnly.isSameOrAfter(excludeStartDate,
|
|
232
|
+
const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
|
|
233
|
+
const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
|
|
234
|
+
if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
|
|
311
235
|
return false;
|
|
312
236
|
}
|
|
313
237
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
const ruleEndDate = (0, _dayjs.default)(repeat_rule.end.end_date);
|
|
318
|
-
if (targetDateOnly.isAfter(ruleEndDate, 'day')) {
|
|
238
|
+
if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
|
|
239
|
+
const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
|
|
240
|
+
if (targetDateOnly.isAfter(ruleEndDate, "day")) {
|
|
319
241
|
return false;
|
|
320
242
|
}
|
|
321
243
|
}
|
|
322
|
-
|
|
323
|
-
// 检查目标日期是否在重复规则范围内
|
|
324
244
|
let isDateValid = false;
|
|
325
245
|
switch (repeat_type) {
|
|
326
|
-
case
|
|
246
|
+
case "daily":
|
|
327
247
|
isDateValid = isInDailyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
328
248
|
break;
|
|
329
|
-
case
|
|
249
|
+
case "weekly":
|
|
330
250
|
isDateValid = isInWeeklyRepeatForDate(targetDateOnly, startDate, repeat_rule);
|
|
331
251
|
break;
|
|
332
252
|
default:
|
|
333
253
|
return false;
|
|
334
254
|
}
|
|
335
|
-
|
|
336
|
-
// 如果日期有效,检查时间段
|
|
337
255
|
if (isDateValid) {
|
|
338
256
|
return checkTimeSlotsForDate(targetDate, targetDateString, schedule.time_slot);
|
|
339
257
|
}
|
|
340
258
|
return false;
|
|
341
259
|
};
|
|
342
|
-
|
|
343
|
-
// 检查目标时间是否在某个时间段内(使用目标日期 + time_slot 时间)
|
|
344
|
-
const checkTimeSlotsForDate = (targetDate, targetDateString, timeSlots) => {
|
|
260
|
+
var checkTimeSlotsForDate = (targetDate, targetDateString, timeSlots) => {
|
|
345
261
|
for (const timeSlot of timeSlots) {
|
|
346
262
|
const slotStart = `${targetDateString} ${timeSlot.start_time}:00`;
|
|
347
263
|
const slotEnd = `${targetDateString} ${timeSlot.end_time}:00`;
|
|
348
|
-
const slotStartDate = (0,
|
|
349
|
-
const slotEndDate = (0,
|
|
264
|
+
const slotStartDate = (0, import_dayjs.default)(slotStart);
|
|
265
|
+
const slotEndDate = (0, import_dayjs.default)(slotEnd);
|
|
350
266
|
if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
|
|
351
267
|
return true;
|
|
352
268
|
}
|
|
353
269
|
}
|
|
354
270
|
return false;
|
|
355
271
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const isInDailyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
359
|
-
const daysDiff = targetDate.diff(startDate, 'day');
|
|
272
|
+
var isInDailyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
273
|
+
const daysDiff = targetDate.diff(startDate, "day");
|
|
360
274
|
if (daysDiff < 0) {
|
|
361
275
|
return false;
|
|
362
276
|
}
|
|
363
|
-
|
|
364
|
-
// 检查频率
|
|
365
277
|
return daysDiff % repeatRule.frequency === 0;
|
|
366
278
|
};
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
370
|
-
const targetDayOfWeek = targetDate.day(); // 0=周日, 1=周一, ..., 6=周六
|
|
371
|
-
|
|
372
|
-
// 检查是否在指定的星期几内
|
|
279
|
+
var isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
|
|
280
|
+
const targetDayOfWeek = targetDate.day();
|
|
373
281
|
if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
|
|
374
282
|
return false;
|
|
375
283
|
}
|
|
376
|
-
|
|
377
|
-
// 计算周差
|
|
378
|
-
const weeksDiff = targetDate.diff(startDate, 'week');
|
|
284
|
+
const weeksDiff = targetDate.diff(startDate, "week");
|
|
379
285
|
if (weeksDiff < 0) {
|
|
380
286
|
return false;
|
|
381
287
|
}
|
|
382
|
-
|
|
383
|
-
// 检查频率
|
|
384
288
|
return weeksDiff % repeatRule.frequency === 0;
|
|
385
289
|
};
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* 根据预约时间过滤优惠券列表
|
|
389
|
-
* @param discountList 优惠券列表
|
|
390
|
-
* @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
|
|
391
|
-
* @returns 过滤后的优惠券列表
|
|
392
|
-
*/
|
|
393
|
-
const filterDiscountListByBookingTime = (discountList, bookingTime) => {
|
|
290
|
+
var filterDiscountListByBookingTime = (discountList, bookingTime) => {
|
|
394
291
|
if (!bookingTime) {
|
|
395
292
|
return discountList;
|
|
396
293
|
}
|
|
397
|
-
return discountList.filter(discount => {
|
|
398
|
-
|
|
399
|
-
|
|
294
|
+
return discountList.filter((discount) => {
|
|
295
|
+
var _a, _b;
|
|
296
|
+
if (((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) === "custom_schedule_validity") {
|
|
297
|
+
return getDateIsInSchedule(bookingTime, ((_b = discount.custom_schedule_snapshot) == null ? void 0 : _b.data) || []);
|
|
400
298
|
}
|
|
401
299
|
try {
|
|
402
300
|
const isHasStart = !!discount.start_date && !!discount.start_time;
|
|
403
|
-
const startDate = (0,
|
|
404
|
-
const bookingTimeDayjs = (0,
|
|
405
|
-
|
|
406
|
-
// 判断预约时间是否在开始时间之后
|
|
301
|
+
const startDate = (0, import_dayjs.default)(`${discount.start_date} ${discount.start_time}`);
|
|
302
|
+
const bookingTimeDayjs = (0, import_dayjs.default)(bookingTime);
|
|
407
303
|
const isAfterStart = isHasStart ? bookingTimeDayjs.isSameOrAfter(startDate) : true;
|
|
408
|
-
|
|
409
|
-
// 判断预约时间是否在过期时间之前(expire_time 为空时为长期有效)
|
|
410
|
-
const isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore((0, _dayjs.default)(discount.expire_time)) : true;
|
|
304
|
+
const isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore((0, import_dayjs.default)(discount.expire_time)) : true;
|
|
411
305
|
return isAfterStart && isBeforeExpire;
|
|
412
306
|
} catch (error) {
|
|
413
307
|
return true;
|
|
414
308
|
}
|
|
415
309
|
});
|
|
416
310
|
};
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
* @returns 是否是订单级别的固定金额折扣卡
|
|
421
|
-
*/
|
|
422
|
-
exports.filterDiscountListByBookingTime = filterDiscountListByBookingTime;
|
|
423
|
-
const isOrderLevelFixedAmountDiscount = discount => {
|
|
424
|
-
return discount.tag === 'product_discount_card' && discount?.metadata?.discount_card_type === 'fixed_amount' && discount?.metadata?.discount_calculation_mode === 'order_level';
|
|
311
|
+
var isOrderLevelFixedAmountDiscount = (discount) => {
|
|
312
|
+
var _a, _b;
|
|
313
|
+
return discount.tag === "product_discount_card" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.discount_calculation_mode) === "order_level";
|
|
425
314
|
};
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
* 计算订单级别固定金额折扣卡的分摊结果
|
|
429
|
-
* @param discount 折扣卡
|
|
430
|
-
* @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
|
|
431
|
-
* @returns 分摊结果 Map<productId, { discountAmount, difference }>
|
|
432
|
-
* 注意:
|
|
433
|
-
* - discountAmount 是单价折扣金额(不是总折扣金额)
|
|
434
|
-
* - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
|
|
435
|
-
*/
|
|
436
|
-
exports.isOrderLevelFixedAmountDiscount = isOrderLevelFixedAmountDiscount;
|
|
437
|
-
const calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
|
|
438
|
-
const result = new Map();
|
|
315
|
+
var calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
|
|
316
|
+
const result = /* @__PURE__ */ new Map();
|
|
439
317
|
if (applicableProducts.length === 0) {
|
|
440
318
|
return result;
|
|
441
319
|
}
|
|
442
|
-
|
|
443
|
-
// 计算适用商品的总金额(数量 × 单价)
|
|
444
320
|
const totalAmount = applicableProducts.reduce((acc, product) => {
|
|
445
|
-
return new
|
|
321
|
+
return new import_decimal.default(acc).plus(new import_decimal.default(product.amount).mul(product.quantity)).toNumber();
|
|
446
322
|
}, 0);
|
|
447
323
|
if (totalAmount <= 0) {
|
|
448
324
|
return result;
|
|
449
325
|
}
|
|
450
|
-
|
|
451
|
-
// 固定减免金额
|
|
452
|
-
const fixedAmount = new _decimal.default(discount.par_value || 0).toNumber();
|
|
453
|
-
|
|
454
|
-
// 如果固定金额 >= 商品总金额,折扣最高为商品金额(免费)
|
|
326
|
+
const fixedAmount = new import_decimal.default(discount.par_value || 0).toNumber();
|
|
455
327
|
const actualDiscountTotal = Math.min(fixedAmount, totalAmount);
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
// 🔥 分摊公式改为:(单价 / 适用商品总金额) × 固定金额
|
|
461
|
-
// 这样只有一次取整,避免精度损失
|
|
462
|
-
const rawDiscountPerItem = new _decimal.default(product.amount).div(totalAmount).mul(actualDiscountTotal);
|
|
463
|
-
|
|
464
|
-
// 保留两位小数,向下取整(单价折扣)
|
|
465
|
-
const discountAmountPerItem = rawDiscountPerItem.toDecimalPlaces(2, _decimal.default.ROUND_DOWN).toNumber();
|
|
328
|
+
let allocatedTotal = new import_decimal.default(0);
|
|
329
|
+
applicableProducts.forEach((product) => {
|
|
330
|
+
const rawDiscountPerItem = new import_decimal.default(product.amount).div(totalAmount).mul(actualDiscountTotal);
|
|
331
|
+
const discountAmountPerItem = rawDiscountPerItem.toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
|
|
466
332
|
result.set(product.productId, {
|
|
467
333
|
discountAmount: discountAmountPerItem,
|
|
468
334
|
// 单价折扣金额
|
|
469
|
-
difference: 0
|
|
335
|
+
difference: 0
|
|
336
|
+
// 默认差值为0
|
|
470
337
|
});
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
338
|
+
allocatedTotal = allocatedTotal.plus(
|
|
339
|
+
new import_decimal.default(discountAmountPerItem).mul(product.quantity)
|
|
340
|
+
);
|
|
474
341
|
});
|
|
475
|
-
|
|
476
|
-
// 🔥 计算总差值
|
|
477
|
-
// 总差值 = 固定金额 - 所有商品的 (单价折扣 × 数量) 之和
|
|
478
|
-
const totalDifference = new _decimal.default(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, _decimal.default.ROUND_HALF_UP).toNumber();
|
|
342
|
+
const totalDifference = new import_decimal.default(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
|
|
479
343
|
if (totalDifference > 0) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
// 子商品:quantity === 1 且 parentQuantity === 1
|
|
483
|
-
const isSingleQuantity = product => {
|
|
484
|
-
if (product.parentQuantity !== undefined) {
|
|
485
|
-
// 子商品:需要同时满足自身数量为1且主商品数量为1
|
|
344
|
+
const isSingleQuantity = (product) => {
|
|
345
|
+
if (product.parentQuantity !== void 0) {
|
|
486
346
|
return product.quantity === 1 && product.parentQuantity === 1;
|
|
487
347
|
}
|
|
488
|
-
// 主商品:只需要自身数量为1
|
|
489
348
|
return product.quantity === 1;
|
|
490
349
|
};
|
|
491
|
-
|
|
492
|
-
// 🔥 筛选出数量为1的商品
|
|
493
350
|
const singleQuantityProducts = applicableProducts.filter(isSingleQuantity);
|
|
494
351
|
if (singleQuantityProducts.length > 0) {
|
|
495
|
-
|
|
496
|
-
// 剩余空间 = 商品价格 - 当前折扣金额 >= 差值
|
|
497
|
-
const productsWithEnoughSpace = singleQuantityProducts.filter(product => {
|
|
352
|
+
const productsWithEnoughSpace = singleQuantityProducts.filter((product) => {
|
|
498
353
|
const allocation = result.get(product.productId);
|
|
499
|
-
if (!allocation)
|
|
500
|
-
|
|
354
|
+
if (!allocation)
|
|
355
|
+
return false;
|
|
356
|
+
const remainingSpace = new import_decimal.default(product.amount).minus(allocation.discountAmount).toNumber();
|
|
501
357
|
return remainingSpace >= totalDifference;
|
|
502
358
|
});
|
|
503
359
|
if (productsWithEnoughSpace.length > 0) {
|
|
504
|
-
// 按金额降序排序,选择金额最大的
|
|
505
360
|
productsWithEnoughSpace.sort((a, b) => b.amount - a.amount);
|
|
506
361
|
const targetProduct = productsWithEnoughSpace[0];
|
|
507
362
|
const targetAllocation = result.get(targetProduct.productId);
|
|
508
363
|
if (targetAllocation) {
|
|
509
|
-
// 差值直接加到折扣金额上
|
|
510
364
|
result.set(targetProduct.productId, {
|
|
511
|
-
discountAmount: new
|
|
512
|
-
difference: 0
|
|
365
|
+
discountAmount: new import_decimal.default(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
|
|
366
|
+
difference: 0
|
|
367
|
+
// 不需要存储差值
|
|
513
368
|
});
|
|
514
369
|
}
|
|
515
370
|
} else {
|
|
516
|
-
// 🔥 优先级2:所有数量为1的商品都没有足够剩余空间
|
|
517
|
-
// 选择金额最大的商品,差值存储在metadata中
|
|
518
371
|
singleQuantityProducts.sort((a, b) => b.amount - a.amount);
|
|
519
372
|
const targetProduct = singleQuantityProducts[0];
|
|
520
373
|
const targetAllocation = result.get(targetProduct.productId);
|
|
@@ -526,8 +379,6 @@ const calculateOrderLevelDiscountAllocation = (discount, applicableProducts) =>
|
|
|
526
379
|
}
|
|
527
380
|
}
|
|
528
381
|
} else {
|
|
529
|
-
// 🔥 优先级3:没有数量为1的商品,走原有逻辑
|
|
530
|
-
// 差值存储在最后一个商品的metadata中
|
|
531
382
|
const lastProduct = applicableProducts[applicableProducts.length - 1];
|
|
532
383
|
const lastProductAllocation = result.get(lastProduct.productId);
|
|
533
384
|
if (lastProductAllocation) {
|
|
@@ -540,4 +391,16 @@ const calculateOrderLevelDiscountAllocation = (discount, applicableProducts) =>
|
|
|
540
391
|
}
|
|
541
392
|
return result;
|
|
542
393
|
};
|
|
543
|
-
|
|
394
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
395
|
+
0 && (module.exports = {
|
|
396
|
+
calculateOrderLevelDiscountAllocation,
|
|
397
|
+
filterDiscountListByBookingTime,
|
|
398
|
+
getDateIsInSchedule,
|
|
399
|
+
getDiscountAmount,
|
|
400
|
+
getDiscountListAmount,
|
|
401
|
+
getDiscountListAmountTotal,
|
|
402
|
+
isAllNormalProduct,
|
|
403
|
+
isNormalProductByDurationSchedule,
|
|
404
|
+
isOrderLevelFixedAmountDiscount,
|
|
405
|
+
uniqueById
|
|
406
|
+
});
|