@pisell/pisellos 2.3.73 → 2.3.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +111 -71
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/model/strategy/adapter/walletPass/example.js +3 -26
- package/dist/model/strategy/strategy-example.js +5 -19
- package/dist/modules/Cart/index.js +0 -3
- package/dist/modules/Cart/utils/cartProduct.js +0 -1
- package/dist/modules/Date/index.js +1 -5
- package/dist/modules/Discount/index.js +2 -4
- package/dist/modules/OpenData/index.js +0 -2
- package/dist/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/index.js +36 -64
- package/dist/modules/Payment/index.js +97 -162
- package/dist/modules/Quotation/index.d.ts +6 -0
- package/dist/modules/Quotation/index.js +75 -19
- package/dist/modules/Rules/index.js +1 -4
- package/dist/modules/Schedule/index.js +0 -1
- package/dist/modules/Schedule/utils.js +0 -1
- package/dist/modules/Step/index.js +0 -1
- package/dist/plugins/request.d.ts +1 -0
- package/dist/plugins/request.js +1 -4
- package/dist/plugins/window.js +2 -6
- package/dist/server/index.d.ts +8 -2
- package/dist/server/index.js +303 -269
- package/dist/server/modules/floor-plan/index.d.ts +4 -0
- package/dist/server/modules/floor-plan/index.js +240 -98
- package/dist/server/modules/menu/index.js +75 -59
- package/dist/server/modules/order/index.d.ts +17 -7
- package/dist/server/modules/order/index.js +421 -211
- package/dist/server/modules/products/index.d.ts +8 -2
- package/dist/server/modules/products/index.js +191 -117
- package/dist/server/modules/quotation/index.js +29 -38
- package/dist/server/modules/resource/index.js +24 -17
- package/dist/server/modules/schedule/index.js +27 -35
- package/dist/server/utils/product.js +0 -1
- package/dist/solution/BaseSales/index.js +38 -41
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/index.js +7 -59
- package/dist/solution/BookingByStep/utils/capacity.js +1 -11
- package/dist/solution/BookingByStep/utils/resources.js +1 -3
- package/dist/solution/BookingByStep/utils/timeslots.js +2 -43
- package/dist/solution/BookingTicket/index.js +0 -2
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +6 -7
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +25 -31
- package/dist/solution/BookingTicket/utils/scan/index.js +6 -10
- package/dist/solution/BuyTickets/index.js +9 -12
- package/dist/solution/Checkout/index.js +177 -252
- package/dist/solution/Checkout/utils/index.js +4 -16
- package/dist/solution/RegisterAndLogin/index.js +30 -76
- package/dist/solution/ScanOrder/index.js +50 -60
- package/dist/solution/ShopDiscount/index.js +2 -7
- package/dist/solution/VenueBooking/index.js +45 -55
- package/dist/utils/task.js +15 -18
- package/dist/utils/watch.js +0 -1
- package/lib/apis/picoding.js +2 -0
- package/lib/core/index.d.ts +7 -0
- package/lib/core/index.js +149 -131
- package/lib/effects/index.js +46 -57
- package/lib/index.js +82 -49
- package/lib/model/index.js +14 -21
- package/lib/model/strategy/adapter/dataVariant/adapter.js +38 -50
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +162 -236
- package/lib/model/strategy/adapter/dataVariant/examples.js +229 -237
- package/lib/model/strategy/adapter/dataVariant/index.js +39 -34
- package/lib/model/strategy/adapter/dataVariant/type.js +57 -28
- package/lib/model/strategy/adapter/index.js +100 -64
- package/lib/model/strategy/adapter/itemRule/adapter.js +156 -144
- package/lib/model/strategy/adapter/itemRule/evaluator.js +36 -48
- package/lib/model/strategy/adapter/itemRule/examples.js +295 -225
- package/lib/model/strategy/adapter/itemRule/index.js +83 -57
- package/lib/model/strategy/adapter/itemRule/type.js +97 -36
- package/lib/model/strategy/adapter/promotion/adapter.js +91 -69
- package/lib/model/strategy/adapter/promotion/evaluator.js +444 -310
- package/lib/model/strategy/adapter/promotion/examples.js +222 -234
- package/lib/model/strategy/adapter/promotion/index.js +1 -0
- package/lib/model/strategy/adapter/promotion/type.js +243 -36
- package/lib/model/strategy/adapter/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/evaluator.js +180 -150
- package/lib/model/strategy/adapter/walletPass/example.js +217 -190
- package/lib/model/strategy/adapter/walletPass/index.js +75 -51
- package/lib/model/strategy/adapter/walletPass/locales.js +36 -58
- package/lib/model/strategy/adapter/walletPass/type.js +4 -16
- package/lib/model/strategy/adapter/walletPass/utils.js +588 -378
- package/lib/model/strategy/engine.js +270 -168
- package/lib/model/strategy/index.js +49 -34
- package/lib/model/strategy/strategy-example.js +243 -239
- package/lib/model/strategy/type.js +100 -40
- package/lib/modules/Account/index.js +39 -53
- package/lib/modules/Account/types.js +20 -33
- package/lib/modules/AccountList/index.js +116 -154
- package/lib/modules/AccountList/types.js +30 -31
- package/lib/modules/AccountList/utils.js +18 -30
- package/lib/modules/BaseModule.js +23 -42
- package/lib/modules/BookingContext/index.js +158 -136
- package/lib/modules/BookingContext/types.js +46 -32
- package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +138 -146
- package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +78 -83
- package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +170 -150
- package/lib/modules/BookingContext/utils/flexible.js +38 -55
- package/lib/modules/BookingContext/utils/formatResourceList.js +19 -34
- package/lib/modules/BookingContext/utils/index.js +124 -41
- package/lib/modules/BookingContext/utils/noResource.js +58 -70
- package/lib/modules/BookingContext/utils/orderLineDisplay.js +14 -41
- package/lib/modules/BookingContext/utils/productExtend.js +202 -155
- package/lib/modules/BookingContext/utils/resourceErrors.js +53 -53
- package/lib/modules/BookingContext/utils/resourceSelection.js +19 -41
- package/lib/modules/BookingContext/utils/resources.js +209 -167
- package/lib/modules/BookingContext/utils/serviceTimes.js +115 -116
- package/lib/modules/BookingContext/utils/timeSlices.js +76 -86
- package/lib/modules/Cart/index.js +170 -124
- package/lib/modules/Cart/types.js +46 -51
- package/lib/modules/Cart/utils/cartAccount.js +40 -39
- package/lib/modules/Cart/utils/cartDate.js +56 -61
- package/lib/modules/Cart/utils/cartDiscount.js +28 -33
- package/lib/modules/Cart/utils/cartNote.js +27 -32
- package/lib/modules/Cart/utils/cartProduct.js +321 -251
- package/lib/modules/Cart/utils/cartRelationForms.js +29 -35
- package/lib/modules/Cart/utils/cartResource.js +70 -78
- package/lib/modules/Cart/utils/changePrice.js +22 -50
- package/lib/modules/Cart/utils/index.js +106 -48
- package/lib/modules/Customer/constants.js +13 -34
- package/lib/modules/Customer/index.js +235 -172
- package/lib/modules/Customer/types.js +38 -35
- package/lib/modules/Date/index.js +116 -115
- package/lib/modules/Date/types.js +16 -28
- package/lib/modules/Date/utils.js +174 -123
- package/lib/modules/Discount/index.js +122 -127
- package/lib/modules/Discount/types.js +9 -31
- package/lib/modules/Guests/index.js +30 -56
- package/lib/modules/Guests/types.js +23 -33
- package/lib/modules/Holder/index.js +209 -189
- package/lib/modules/Holder/types.js +4 -16
- package/lib/modules/Holder/utils.js +20 -49
- package/lib/modules/OpenData/index.js +70 -76
- package/lib/modules/OpenData/types.js +4 -16
- package/lib/modules/OpenData/utils.js +44 -78
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/index.js +1713 -2118
- package/lib/modules/Order/payment-utils.js +77 -120
- package/lib/modules/Order/types.js +88 -35
- package/lib/modules/Order/utils/bundleDiscountHydration.js +41 -74
- package/lib/modules/Order/utils/discountProductLineIdentity.js +142 -100
- package/lib/modules/Order/utils/manualProductDiscount.js +124 -123
- package/lib/modules/Order/utils/orderCollectionIdentity.js +184 -244
- package/lib/modules/Order/utils.js +814 -647
- package/lib/modules/Payment/cash.js +20 -33
- package/lib/modules/Payment/cashRecommendationAlgorithm.js +145 -76
- package/lib/modules/Payment/eftpos.js +16 -30
- package/lib/modules/Payment/index.js +532 -399
- package/lib/modules/Payment/mx51.js +1 -0
- package/lib/modules/Payment/types.js +230 -108
- package/lib/modules/Payment/utils.js +52 -51
- package/lib/modules/Payment/walletpass.js +485 -660
- package/lib/modules/Product/index.js +51 -46
- package/lib/modules/Product/types.js +4 -16
- package/lib/modules/Product/utils.js +32 -33
- package/lib/modules/ProductList/index.js +113 -123
- package/lib/modules/ProductList/types.js +9 -31
- package/lib/modules/Quotation/index.d.ts +6 -0
- package/lib/modules/Quotation/index.js +110 -103
- package/lib/modules/Quotation/types.js +4 -16
- package/lib/modules/Resource/index.js +27 -59
- package/lib/modules/Resource/types.js +22 -32
- package/lib/modules/Resource/utils.js +30 -38
- package/lib/modules/ResourcePlanner/index.js +25 -23
- package/lib/modules/ResourcePlanner/localClock.js +54 -119
- package/lib/modules/ResourcePlanner/planner.js +589 -770
- package/lib/modules/ResourcePlanner/types.js +10 -29
- package/lib/modules/Rules/index.js +1218 -959
- package/lib/modules/Rules/types.js +17 -40
- package/lib/modules/SalesSummary/index.js +85 -90
- package/lib/modules/SalesSummary/types.js +4 -16
- package/lib/modules/SalesSummary/utils.js +355 -430
- package/lib/modules/ScanOrderLogger/index.js +59 -79
- package/lib/modules/ScanOrderLogger/providers/feishu.js +54 -78
- package/lib/modules/ScanOrderLogger/providers/grafana.js +13 -36
- package/lib/modules/ScanOrderLogger/types.js +4 -16
- package/lib/modules/Schedule/getDateIsInSchedule.js +334 -163
- package/lib/modules/Schedule/index.js +100 -114
- package/lib/modules/Schedule/type.js +4 -16
- package/lib/modules/Schedule/types.js +4 -16
- package/lib/modules/Schedule/utils.js +433 -291
- package/lib/modules/Step/index.js +40 -52
- package/lib/modules/Step/tyeps.js +4 -16
- package/lib/modules/Summary/index.js +66 -71
- package/lib/modules/Summary/types.js +4 -16
- package/lib/modules/Summary/utils.js +773 -418
- package/lib/modules/SurchargeList/index.js +46 -60
- package/lib/modules/SurchargeList/types.js +4 -16
- package/lib/modules/index.js +245 -63
- package/lib/plugins/app.js +4 -16
- package/lib/plugins/index.js +36 -25
- package/lib/plugins/request.d.ts +1 -0
- package/lib/plugins/request.js +137 -126
- package/lib/plugins/shopStore.js +4 -16
- package/lib/plugins/user.js +4 -16
- package/lib/plugins/window.js +171 -179
- package/lib/server/index.d.ts +8 -2
- package/lib/server/index.js +3083 -2663
- package/lib/server/modules/floor-plan/index.d.ts +4 -0
- package/lib/server/modules/floor-plan/index.js +159 -127
- package/lib/server/modules/floor-plan/types.js +15 -30
- package/lib/server/modules/index.js +106 -68
- package/lib/server/modules/menu/index.js +170 -124
- package/lib/server/modules/menu/types.js +18 -31
- package/lib/server/modules/order/index.d.ts +17 -7
- package/lib/server/modules/order/index.js +916 -977
- package/lib/server/modules/order/types.js +122 -33
- package/lib/server/modules/order/utils/filterBookings.js +219 -194
- package/lib/server/modules/order/utils/filterOrders.js +118 -92
- package/lib/server/modules/payment/index.js +59 -83
- package/lib/server/modules/payment/types.js +4 -16
- package/lib/server/modules/products/index.d.ts +8 -2
- package/lib/server/modules/products/index.js +656 -471
- package/lib/server/modules/products/types.js +44 -34
- package/lib/server/modules/quotation/index.js +137 -172
- package/lib/server/modules/quotation/types.js +21 -31
- package/lib/server/modules/resource/index.js +225 -186
- package/lib/server/modules/resource/types.js +42 -33
- package/lib/server/modules/schedule/index.js +135 -123
- package/lib/server/modules/schedule/types.js +14 -21
- package/lib/server/modules/schedule/utils.js +334 -163
- package/lib/server/types.js +4 -16
- package/lib/server/utils/index.js +25 -23
- package/lib/server/utils/product.js +196 -139
- package/lib/server/utils/schedule.js +34 -41
- package/lib/server/utils/small-ticket.js +479 -456
- package/lib/server/utils/time.js +40 -49
- package/lib/solution/BaseSales/index.js +1186 -1410
- package/lib/solution/BaseSales/types.js +42 -38
- package/lib/solution/BaseSales/utils/cartPromotion.js +642 -498
- package/lib/solution/BaseSales/utils/parseSalesResponse.js +85 -105
- package/lib/solution/BaseSales/utils/quotationPrice.js +56 -114
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +108 -145
- package/lib/solution/BaseSales/utils.js +158 -143
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/index.js +1527 -1340
- package/lib/solution/BookingByStep/types.js +40 -99
- package/lib/solution/BookingByStep/utils/capacity.js +192 -160
- package/lib/solution/BookingByStep/utils/products.js +42 -52
- package/lib/solution/BookingByStep/utils/resources.js +527 -330
- package/lib/solution/BookingByStep/utils/stock.js +65 -44
- package/lib/solution/BookingByStep/utils/timeslots.js +129 -131
- package/lib/solution/BookingTicket/index.js +607 -522
- package/lib/solution/BookingTicket/types.js +99 -77
- package/lib/solution/BookingTicket/utils/addProductDecision.js +226 -189
- package/lib/solution/BookingTicket/utils/addTimeAvailability.js +58 -89
- package/lib/solution/BookingTicket/utils/bookingStatus.js +107 -78
- package/lib/solution/BookingTicket/utils/cartView.js +114 -99
- package/lib/solution/BookingTicket/utils/exampleData.js +185 -0
- package/lib/solution/BookingTicket/utils/orderCustomer.js +18 -41
- package/lib/solution/BookingTicket/utils/resolveBestAddTimePlan.js +219 -86
- package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +168 -116
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +79 -91
- package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +54 -41
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +84 -81
- package/lib/solution/BookingTicket/utils/scan/index.js +98 -104
- package/lib/solution/BookingTicket/utils/scan/scanCache.js +90 -43
- package/lib/solution/BookingTicket/utils/scan/scanProductValues.js +52 -64
- package/lib/solution/BookingTicket/utils/sessionCatalogStale.js +56 -58
- package/lib/solution/BookingTicket/utils/weighingProductSku.js +34 -48
- package/lib/solution/BuyTickets/index.js +67 -70
- package/lib/solution/BuyTickets/types.js +22 -38
- package/lib/solution/Checkout/index.js +1451 -1158
- package/lib/solution/Checkout/types.js +91 -61
- package/lib/solution/Checkout/utils/index.js +228 -156
- package/lib/solution/PlaceOrder/index.js +55 -0
- package/lib/solution/RegisterAndLogin/config.js +493 -460
- package/lib/solution/RegisterAndLogin/index.js +633 -630
- package/lib/solution/RegisterAndLogin/types.js +189 -76
- package/lib/solution/RegisterAndLogin/utils.js +183 -125
- package/lib/solution/Sales/index.js +328 -324
- package/lib/solution/Sales/types.js +27 -33
- package/lib/solution/ScanOrder/index.js +832 -864
- package/lib/solution/ScanOrder/types.js +33 -34
- package/lib/solution/ScanOrder/utils.js +409 -374
- package/lib/solution/ShopDiscount/index.js +226 -232
- package/lib/solution/ShopDiscount/types.js +15 -37
- package/lib/solution/ShopDiscount/utils.js +300 -172
- package/lib/solution/UnifiedBookingSales/index.js +1035 -1201
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +99 -159
- package/lib/solution/UnifiedBookingSales/types.js +10 -32
- package/lib/solution/VenueBooking/index.js +811 -879
- package/lib/solution/VenueBooking/types.js +19 -39
- package/lib/solution/VenueBooking/utils/dateSummary.js +27 -56
- package/lib/solution/VenueBooking/utils/resource.js +31 -54
- package/lib/solution/VenueBooking/utils/slotMerge.js +94 -107
- package/lib/solution/VenueBooking/utils/timeSlot.js +132 -132
- package/lib/solution/VenueBooking/utils.js +130 -67
- package/lib/solution/index.js +124 -41
- package/lib/store/createStore.js +32 -29
- package/lib/types/index.js +4 -16
- package/lib/utils/payment-number.js +26 -46
- package/lib/utils/task.js +36 -36
- package/lib/utils/watch.js +81 -47
- package/package.json +2 -1
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
"use strict";
|
|
18
2
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
__export(evaluator_exports, {
|
|
22
|
-
DataVariantEvaluator: () => DataVariantEvaluator,
|
|
23
|
-
default: () => evaluator_default
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
24
5
|
});
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
|
|
6
|
+
exports.default = exports.DataVariantEvaluator = void 0;
|
|
7
|
+
var _engine = require("../../engine");
|
|
8
|
+
var _getDateIsInSchedule = require("../../../../modules/Schedule/getDateIsInSchedule");
|
|
9
|
+
var _adapter = require("./adapter");
|
|
10
|
+
/**
|
|
11
|
+
* Data Variant 评估器。
|
|
12
|
+
*
|
|
13
|
+
* 当前阶段只提供策略模型能力和示例验证,不接入 ProductList 业务链路。
|
|
14
|
+
*/
|
|
15
|
+
class DataVariantEvaluator {
|
|
16
|
+
adapter;
|
|
17
|
+
strategyConfigs = [];
|
|
30
18
|
constructor() {
|
|
31
|
-
this.
|
|
32
|
-
this.adapter = new import_adapter.DataVariantAdapter();
|
|
19
|
+
this.adapter = new _adapter.DataVariantAdapter();
|
|
33
20
|
}
|
|
21
|
+
|
|
34
22
|
/**
|
|
35
23
|
* 设置策略配置列表,仅保留 metadata.type === 'data_variant' 的策略。
|
|
36
24
|
*/
|
|
@@ -40,6 +28,7 @@ var DataVariantEvaluator = class {
|
|
|
40
28
|
getStrategyConfigs() {
|
|
41
29
|
return this.strategyConfigs;
|
|
42
30
|
}
|
|
31
|
+
|
|
43
32
|
/**
|
|
44
33
|
* 批量解析商品 Data Variant。
|
|
45
34
|
*
|
|
@@ -48,28 +37,15 @@ var DataVariantEvaluator = class {
|
|
|
48
37
|
resolveProducts(businessData) {
|
|
49
38
|
const strategyConfigs = businessData.strategyConfigs ? this.normalizeStrategyConfigs(businessData.strategyConfigs) : this.strategyConfigs;
|
|
50
39
|
const menuScopeMap = this.buildMenuScopeMap(businessData.menuList || []);
|
|
51
|
-
const scheduleTimePoints = this.buildScheduleTimePoints(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
businessData,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const products = businessData.products.map((product) => {
|
|
61
|
-
const resolvedProduct = this.resolveProduct(
|
|
62
|
-
product,
|
|
63
|
-
businessData,
|
|
64
|
-
globalEffectiveRuleMap,
|
|
65
|
-
menuScopeMap
|
|
66
|
-
);
|
|
67
|
-
return this.resolveProductBundleItems(
|
|
68
|
-
resolvedProduct,
|
|
69
|
-
businessData,
|
|
70
|
-
globalEffectiveRuleMap,
|
|
71
|
-
menuScopeMap
|
|
72
|
-
);
|
|
40
|
+
const scheduleTimePoints = this.buildScheduleTimePoints(strategyConfigs, businessData.scheduleList || []);
|
|
41
|
+
const {
|
|
42
|
+
globalEffectiveRuleMap,
|
|
43
|
+
rawResults
|
|
44
|
+
} = this.buildGlobalEffectiveRuleMap(strategyConfigs, businessData, menuScopeMap);
|
|
45
|
+
const products = businessData.products.map(product => {
|
|
46
|
+
const resolvedProduct = this.resolveProduct(product, businessData, globalEffectiveRuleMap, menuScopeMap);
|
|
47
|
+
// 套餐子商品也可能携带 data_variants,需在同一策略上下文内继续评估并写回 bundle_item。
|
|
48
|
+
return this.resolveProductBundleItems(resolvedProduct, businessData, globalEffectiveRuleMap, menuScopeMap);
|
|
73
49
|
});
|
|
74
50
|
return {
|
|
75
51
|
products,
|
|
@@ -79,55 +55,51 @@ var DataVariantEvaluator = class {
|
|
|
79
55
|
rawResults
|
|
80
56
|
};
|
|
81
57
|
}
|
|
58
|
+
|
|
82
59
|
/**
|
|
83
60
|
* 根据 operator/field 判断条件是否依赖当前商品。
|
|
84
61
|
*/
|
|
85
62
|
getConditionScope(rule) {
|
|
86
|
-
if (rule.operator ===
|
|
87
|
-
|
|
88
|
-
if (rule.operator ===
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return "product";
|
|
92
|
-
if (rule.field === "product" || rule.field === "productIdAndVariantId") {
|
|
93
|
-
return "product";
|
|
63
|
+
if (rule.operator === 'schedule_match') return 'global';
|
|
64
|
+
if (rule.operator === 'menu_match') return 'product';
|
|
65
|
+
if (rule.operator === 'product_match') return 'product';
|
|
66
|
+
if (rule.field === 'product' || rule.field === 'productIdAndVariantId') {
|
|
67
|
+
return 'product';
|
|
94
68
|
}
|
|
95
|
-
return
|
|
69
|
+
return 'global';
|
|
96
70
|
}
|
|
71
|
+
|
|
97
72
|
/**
|
|
98
73
|
* 将餐牌 partyroom_package 预构建为 Map/Set 索引。
|
|
99
74
|
*/
|
|
100
75
|
buildMenuScopeMap(menuList) {
|
|
101
|
-
const map =
|
|
76
|
+
const map = new Map();
|
|
102
77
|
for (const menu of menuList) {
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (!menuId)
|
|
107
|
-
continue;
|
|
78
|
+
if (menu?.status && menu.status !== 'valid') continue;
|
|
79
|
+
const menuId = this.toNumber(menu?.form_record_id);
|
|
80
|
+
if (!menuId) continue;
|
|
108
81
|
const scope = {
|
|
109
82
|
isAllProducts: false,
|
|
110
|
-
collectionIds:
|
|
111
|
-
productKeys:
|
|
112
|
-
productAllVariantIds:
|
|
83
|
+
collectionIds: new Set(),
|
|
84
|
+
productKeys: new Set(),
|
|
85
|
+
productAllVariantIds: new Set()
|
|
113
86
|
};
|
|
114
87
|
const packageConfig = menu.partyroom_package;
|
|
115
|
-
const products = Array.isArray(packageConfig
|
|
116
|
-
if (
|
|
88
|
+
const products = Array.isArray(packageConfig?.products) ? packageConfig.products : [];
|
|
89
|
+
if (packageConfig?.type === 'product_all') {
|
|
117
90
|
scope.isAllProducts = true;
|
|
118
|
-
} else if (
|
|
91
|
+
} else if (packageConfig?.type === 'product_collection') {
|
|
119
92
|
for (const item of products) {
|
|
120
93
|
const collectionId = this.toNumber(item.product_collection_id);
|
|
121
94
|
if (collectionId) {
|
|
122
95
|
scope.collectionIds.add(collectionId);
|
|
123
96
|
}
|
|
124
97
|
}
|
|
125
|
-
} else if (
|
|
98
|
+
} else if (packageConfig?.type === 'products') {
|
|
126
99
|
for (const item of products) {
|
|
127
100
|
const productId = this.toNumber(item.product_id);
|
|
128
101
|
const variantId = this.toNumber(item.product_variant_id);
|
|
129
|
-
if (!productId)
|
|
130
|
-
continue;
|
|
102
|
+
if (!productId) continue;
|
|
131
103
|
if (variantId === 0) {
|
|
132
104
|
scope.productAllVariantIds.add(productId);
|
|
133
105
|
} else {
|
|
@@ -139,6 +111,7 @@ var DataVariantEvaluator = class {
|
|
|
139
111
|
}
|
|
140
112
|
return map;
|
|
141
113
|
}
|
|
114
|
+
|
|
142
115
|
/**
|
|
143
116
|
* 从当前策略中所有 schedule_match.value 绑定的 schedule_id 提取时间点。
|
|
144
117
|
*
|
|
@@ -146,27 +119,25 @@ var DataVariantEvaluator = class {
|
|
|
146
119
|
*/
|
|
147
120
|
buildScheduleTimePoints(strategyConfigs, scheduleList) {
|
|
148
121
|
const scheduleIds = this.collectScheduleIdsFromStrategies(strategyConfigs);
|
|
149
|
-
if (!scheduleIds.length || !scheduleList.length)
|
|
150
|
-
return [];
|
|
122
|
+
if (!scheduleIds.length || !scheduleList.length) return [];
|
|
151
123
|
const scheduleIdSet = new Set(scheduleIds);
|
|
152
|
-
const matchedSchedules = scheduleList.filter(
|
|
153
|
-
(schedule) => scheduleIdSet.has(Number(schedule.id))
|
|
154
|
-
);
|
|
124
|
+
const matchedSchedules = scheduleList.filter(schedule => scheduleIdSet.has(Number(schedule.id)));
|
|
155
125
|
return this.extractTimePointsFromSchedules(matchedSchedules);
|
|
156
126
|
}
|
|
157
127
|
buildGlobalEffectiveRuleMap(strategyConfigs, businessData, menuScopeMap) {
|
|
158
|
-
const globalEffectiveRuleMap =
|
|
128
|
+
const globalEffectiveRuleMap = new Map();
|
|
159
129
|
const rawResults = [];
|
|
160
130
|
const engine = this.createEngine(businessData, menuScopeMap);
|
|
161
131
|
const context = this.adapter.prepareGlobalContext(businessData);
|
|
162
132
|
for (const config of strategyConfigs) {
|
|
163
|
-
if (!this.isStrategyActive(config))
|
|
164
|
-
|
|
165
|
-
|
|
133
|
+
if (!this.isStrategyActive(config)) continue;
|
|
134
|
+
const {
|
|
135
|
+
globalConfig,
|
|
136
|
+
productRules
|
|
137
|
+
} = this.splitStrategyConfig(config);
|
|
166
138
|
const result = engine.evaluate(globalConfig, context);
|
|
167
139
|
rawResults.push(result);
|
|
168
|
-
if (!result.applicable)
|
|
169
|
-
continue;
|
|
140
|
+
if (!result.applicable) continue;
|
|
170
141
|
globalEffectiveRuleMap.set(String(config.metadata.id), {
|
|
171
142
|
ruleId: String(config.metadata.id),
|
|
172
143
|
priority: this.getStrategyPriority(config),
|
|
@@ -175,19 +146,18 @@ var DataVariantEvaluator = class {
|
|
|
175
146
|
globalResult: result
|
|
176
147
|
});
|
|
177
148
|
}
|
|
178
|
-
return {
|
|
149
|
+
return {
|
|
150
|
+
globalEffectiveRuleMap,
|
|
151
|
+
rawResults
|
|
152
|
+
};
|
|
179
153
|
}
|
|
180
154
|
resolveProduct(product, businessData, globalEffectiveRuleMap, menuScopeMap) {
|
|
181
155
|
const dataVariants = this.getProductDataVariants(product);
|
|
182
|
-
if (!dataVariants.length)
|
|
183
|
-
return product;
|
|
156
|
+
if (!dataVariants.length) return product;
|
|
184
157
|
const matchedVariants = [];
|
|
185
158
|
for (const variant of dataVariants) {
|
|
186
|
-
const rule = globalEffectiveRuleMap.get(
|
|
187
|
-
|
|
188
|
-
);
|
|
189
|
-
if (!rule)
|
|
190
|
-
continue;
|
|
159
|
+
const rule = globalEffectiveRuleMap.get(String(variant.data_variant_rule_id));
|
|
160
|
+
if (!rule) continue;
|
|
191
161
|
if (!this.evaluateProductRules(rule, product, businessData, menuScopeMap)) {
|
|
192
162
|
continue;
|
|
193
163
|
}
|
|
@@ -198,10 +168,10 @@ var DataVariantEvaluator = class {
|
|
|
198
168
|
variant
|
|
199
169
|
});
|
|
200
170
|
}
|
|
201
|
-
if (!matchedVariants.length)
|
|
202
|
-
return product;
|
|
171
|
+
if (!matchedVariants.length) return product;
|
|
203
172
|
return this.mergeMatchedVariants(product, matchedVariants);
|
|
204
173
|
}
|
|
174
|
+
|
|
205
175
|
/**
|
|
206
176
|
* 解析套餐子商品上的 Data Variant 覆盖。
|
|
207
177
|
*
|
|
@@ -212,21 +182,14 @@ var DataVariantEvaluator = class {
|
|
|
212
182
|
if (!Array.isArray(bundleGroups) || bundleGroups.length === 0) {
|
|
213
183
|
return product;
|
|
214
184
|
}
|
|
215
|
-
const resolvedGroups = bundleGroups.map(
|
|
216
|
-
const bundleItems = group
|
|
185
|
+
const resolvedGroups = bundleGroups.map(group => {
|
|
186
|
+
const bundleItems = group?.bundle_item;
|
|
217
187
|
if (!Array.isArray(bundleItems) || bundleItems.length === 0) {
|
|
218
188
|
return group;
|
|
219
189
|
}
|
|
220
190
|
return {
|
|
221
191
|
...group,
|
|
222
|
-
bundle_item: bundleItems.map(
|
|
223
|
-
(item) => this.resolveBundleItem(
|
|
224
|
-
item,
|
|
225
|
-
businessData,
|
|
226
|
-
globalEffectiveRuleMap,
|
|
227
|
-
menuScopeMap
|
|
228
|
-
)
|
|
229
|
-
)
|
|
192
|
+
bundle_item: bundleItems.map(item => this.resolveBundleItem(item, businessData, globalEffectiveRuleMap, menuScopeMap))
|
|
230
193
|
};
|
|
231
194
|
});
|
|
232
195
|
return {
|
|
@@ -234,6 +197,7 @@ var DataVariantEvaluator = class {
|
|
|
234
197
|
bundle_group: resolvedGroups
|
|
235
198
|
};
|
|
236
199
|
}
|
|
200
|
+
|
|
237
201
|
/**
|
|
238
202
|
* 将 bundle_item 转为 DataVariantProduct 并评估 data_variants。
|
|
239
203
|
*/
|
|
@@ -242,14 +206,10 @@ var DataVariantEvaluator = class {
|
|
|
242
206
|
if (!this.getProductDataVariants(bundleProduct).length) {
|
|
243
207
|
return item;
|
|
244
208
|
}
|
|
245
|
-
const resolvedItem = this.resolveProduct(
|
|
246
|
-
bundleProduct,
|
|
247
|
-
businessData,
|
|
248
|
-
globalEffectiveRuleMap,
|
|
249
|
-
menuScopeMap
|
|
250
|
-
);
|
|
209
|
+
const resolvedItem = this.resolveProduct(bundleProduct, businessData, globalEffectiveRuleMap, menuScopeMap);
|
|
251
210
|
return this.mergeBundleItemResolvedData(item, resolvedItem);
|
|
252
211
|
}
|
|
212
|
+
|
|
253
213
|
/**
|
|
254
214
|
* bundle_item 的商品身份映射:bundle_product_id + bundle_variant_id。
|
|
255
215
|
*/
|
|
@@ -265,18 +225,20 @@ var DataVariantEvaluator = class {
|
|
|
265
225
|
data_variants: item.data_variants
|
|
266
226
|
};
|
|
267
227
|
}
|
|
228
|
+
|
|
268
229
|
/**
|
|
269
230
|
* 仅回写命中的字段,避免污染 bundle_item 的结构字段。
|
|
270
231
|
*/
|
|
271
232
|
mergeBundleItemResolvedData(originalItem, resolvedItem) {
|
|
272
|
-
var _a;
|
|
273
233
|
const appliedInfo = resolvedItem._dataVariant;
|
|
274
|
-
if (!
|
|
234
|
+
if (!appliedInfo?.appliedFields?.length) {
|
|
275
235
|
return originalItem;
|
|
276
236
|
}
|
|
277
|
-
const result = {
|
|
237
|
+
const result = {
|
|
238
|
+
...originalItem
|
|
239
|
+
};
|
|
278
240
|
for (const field of appliedInfo.appliedFields) {
|
|
279
|
-
if (resolvedItem[field] !==
|
|
241
|
+
if (resolvedItem[field] !== undefined) {
|
|
280
242
|
result[field] = resolvedItem[field];
|
|
281
243
|
}
|
|
282
244
|
}
|
|
@@ -284,20 +246,20 @@ var DataVariantEvaluator = class {
|
|
|
284
246
|
return result;
|
|
285
247
|
}
|
|
286
248
|
evaluateProductRules(rule, product, businessData, menuScopeMap) {
|
|
287
|
-
if (!rule.productRules.length)
|
|
288
|
-
return true;
|
|
249
|
+
if (!rule.productRules.length) return true;
|
|
289
250
|
const engine = this.createEngine(businessData, menuScopeMap);
|
|
290
251
|
const context = this.adapter.prepareProductContext(businessData, product);
|
|
291
252
|
const productOnlyConfig = {
|
|
292
253
|
...rule.strategyConfig,
|
|
293
254
|
conditions: {
|
|
294
|
-
operator:
|
|
255
|
+
operator: 'and',
|
|
295
256
|
rules: rule.productRules,
|
|
296
257
|
actionIds: rule.strategyConfig.conditions.actionIds || []
|
|
297
258
|
}
|
|
298
259
|
};
|
|
299
260
|
return engine.evaluate(productOnlyConfig, context).applicable;
|
|
300
261
|
}
|
|
262
|
+
|
|
301
263
|
/**
|
|
302
264
|
* 拆分策略条件。
|
|
303
265
|
*
|
|
@@ -307,7 +269,7 @@ var DataVariantEvaluator = class {
|
|
|
307
269
|
const conditions = config.conditions;
|
|
308
270
|
const globalRules = [];
|
|
309
271
|
const productRules = [];
|
|
310
|
-
if (conditions.operator !==
|
|
272
|
+
if (conditions.operator !== 'and') {
|
|
311
273
|
return {
|
|
312
274
|
globalConfig: {
|
|
313
275
|
...config,
|
|
@@ -321,7 +283,7 @@ var DataVariantEvaluator = class {
|
|
|
321
283
|
productRules.push(...this.flattenConditionRules(rule));
|
|
322
284
|
continue;
|
|
323
285
|
}
|
|
324
|
-
if (this.getConditionScope(rule) ===
|
|
286
|
+
if (this.getConditionScope(rule) === 'product') {
|
|
325
287
|
productRules.push(rule);
|
|
326
288
|
} else {
|
|
327
289
|
globalRules.push(rule);
|
|
@@ -331,7 +293,7 @@ var DataVariantEvaluator = class {
|
|
|
331
293
|
globalConfig: {
|
|
332
294
|
...config,
|
|
333
295
|
conditions: {
|
|
334
|
-
operator:
|
|
296
|
+
operator: 'and',
|
|
335
297
|
rules: globalRules,
|
|
336
298
|
actionIds: conditions.actionIds || []
|
|
337
299
|
}
|
|
@@ -341,62 +303,48 @@ var DataVariantEvaluator = class {
|
|
|
341
303
|
}
|
|
342
304
|
createEngine(businessData, menuScopeMap) {
|
|
343
305
|
const operatorHandlers = {
|
|
344
|
-
schedule_match: (fieldValue, compareValue) => this.evaluateScheduleMatch(
|
|
345
|
-
fieldValue,
|
|
346
|
-
compareValue,
|
|
347
|
-
businessData.scheduleList || []
|
|
348
|
-
),
|
|
306
|
+
schedule_match: (fieldValue, compareValue) => this.evaluateScheduleMatch(fieldValue, compareValue, businessData.scheduleList || []),
|
|
349
307
|
menu_match: (fieldValue, compareValue) => this.evaluateMenuMatch(fieldValue, compareValue, menuScopeMap),
|
|
350
308
|
array_intersects: (fieldValue, compareValue) => this.evaluateArrayIntersects(fieldValue, compareValue)
|
|
351
309
|
};
|
|
352
|
-
return new
|
|
310
|
+
return new _engine.StrategyEngine({
|
|
353
311
|
debug: false,
|
|
354
312
|
enableTrace: false,
|
|
355
313
|
operatorHandlers
|
|
356
314
|
});
|
|
357
315
|
}
|
|
358
316
|
evaluateScheduleMatch(fieldValue, compareValue, scheduleList) {
|
|
359
|
-
const scheduleDateTime = String(fieldValue ||
|
|
317
|
+
const scheduleDateTime = String(fieldValue || '');
|
|
360
318
|
const scheduleIds = this.normalizeNumberArray(compareValue);
|
|
361
|
-
if (!scheduleIds.length)
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
const matchedSchedules = scheduleList.filter(
|
|
366
|
-
(schedule) => scheduleIds.includes(Number(schedule.id))
|
|
367
|
-
);
|
|
368
|
-
return (0, import_getDateIsInSchedule.getDateIsInSchedule)(scheduleDateTime, matchedSchedules);
|
|
319
|
+
if (!scheduleIds.length) return true;
|
|
320
|
+
if (!scheduleDateTime || !scheduleList?.length) return false;
|
|
321
|
+
const matchedSchedules = scheduleList.filter(schedule => scheduleIds.includes(Number(schedule.id)));
|
|
322
|
+
return (0, _getDateIsInSchedule.getDateIsInSchedule)(scheduleDateTime, matchedSchedules);
|
|
369
323
|
}
|
|
370
324
|
evaluateMenuMatch(fieldValue, compareValue, menuScopeMap) {
|
|
371
325
|
const menuIds = this.normalizeNumberArray(compareValue);
|
|
372
|
-
if (!menuIds.length)
|
|
373
|
-
return true;
|
|
326
|
+
if (!menuIds.length) return true;
|
|
374
327
|
for (const menuId of menuIds) {
|
|
375
328
|
const scope = menuScopeMap.get(menuId);
|
|
376
|
-
if (!scope)
|
|
377
|
-
|
|
378
|
-
if (this.isProductInMenuScope(fieldValue, scope))
|
|
379
|
-
return true;
|
|
329
|
+
if (!scope) continue;
|
|
330
|
+
if (this.isProductInMenuScope(fieldValue, scope)) return true;
|
|
380
331
|
}
|
|
381
332
|
return false;
|
|
382
333
|
}
|
|
383
334
|
evaluateArrayIntersects(fieldValue, compareValue) {
|
|
384
335
|
const fieldValues = this.normalizeComparableArray(fieldValue);
|
|
385
336
|
const compareValues = this.normalizeComparableArray(compareValue);
|
|
386
|
-
if (!fieldValues.length || !compareValues.length)
|
|
387
|
-
return false;
|
|
337
|
+
if (!fieldValues.length || !compareValues.length) return false;
|
|
388
338
|
const compareSet = new Set(compareValues);
|
|
389
|
-
return fieldValues.some(
|
|
339
|
+
return fieldValues.some(item => compareSet.has(item));
|
|
390
340
|
}
|
|
391
341
|
collectScheduleIdsFromStrategies(strategyConfigs) {
|
|
392
|
-
const scheduleIds =
|
|
342
|
+
const scheduleIds = new Set();
|
|
393
343
|
for (const config of strategyConfigs) {
|
|
394
|
-
if (!this.isStrategyActive(config))
|
|
395
|
-
continue;
|
|
344
|
+
if (!this.isStrategyActive(config)) continue;
|
|
396
345
|
const rules = this.flattenConditionRules(config.conditions);
|
|
397
346
|
for (const rule of rules) {
|
|
398
|
-
if (rule.operator !==
|
|
399
|
-
continue;
|
|
347
|
+
if (rule.operator !== 'schedule_match') continue;
|
|
400
348
|
for (const scheduleId of this.normalizeNumberArray(rule.value)) {
|
|
401
349
|
scheduleIds.add(scheduleId);
|
|
402
350
|
}
|
|
@@ -405,95 +353,89 @@ var DataVariantEvaluator = class {
|
|
|
405
353
|
return Array.from(scheduleIds);
|
|
406
354
|
}
|
|
407
355
|
extractTimePointsFromSchedules(schedules) {
|
|
408
|
-
const timePoints =
|
|
356
|
+
const timePoints = new Set();
|
|
409
357
|
for (const schedule of schedules) {
|
|
410
358
|
switch (schedule.type) {
|
|
411
|
-
case
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
case "time-slots": {
|
|
417
|
-
const slots = Array.isArray(schedule.time_slot) ? schedule.time_slot : [];
|
|
418
|
-
for (const slot of slots) {
|
|
419
|
-
this.addRawTimePoint(timePoints, slot.start_time);
|
|
420
|
-
this.addRawTimePoint(timePoints, slot.end_time);
|
|
359
|
+
case 'standard':
|
|
360
|
+
{
|
|
361
|
+
this.addDateTimePoint(timePoints, schedule.start_time);
|
|
362
|
+
this.addDateTimePoint(timePoints, schedule.end_time);
|
|
363
|
+
break;
|
|
421
364
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
365
|
+
case 'time-slots':
|
|
366
|
+
{
|
|
367
|
+
const slots = Array.isArray(schedule.time_slot) ? schedule.time_slot : [];
|
|
368
|
+
for (const slot of slots) {
|
|
369
|
+
this.addRawTimePoint(timePoints, slot.start_time);
|
|
370
|
+
this.addRawTimePoint(timePoints, slot.end_time);
|
|
371
|
+
}
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
case 'designation':
|
|
375
|
+
{
|
|
376
|
+
const designations = Array.isArray(schedule.designation) ? schedule.designation : schedule.designation ? [schedule.designation] : [];
|
|
377
|
+
for (const designation of designations) {
|
|
378
|
+
this.addRawTimePoint(timePoints, designation.start_time);
|
|
379
|
+
this.addRawTimePoint(timePoints, designation.end_time);
|
|
380
|
+
}
|
|
381
|
+
break;
|
|
429
382
|
}
|
|
430
|
-
break;
|
|
431
|
-
}
|
|
432
383
|
default:
|
|
433
384
|
break;
|
|
434
385
|
}
|
|
435
386
|
}
|
|
436
|
-
return Array.from(timePoints).sort(
|
|
437
|
-
(a, b) => this.timeToMinutes(a) - this.timeToMinutes(b)
|
|
438
|
-
);
|
|
387
|
+
return Array.from(timePoints).sort((a, b) => this.timeToMinutes(a) - this.timeToMinutes(b));
|
|
439
388
|
}
|
|
440
389
|
addDateTimePoint(points, value) {
|
|
441
390
|
const time = this.extractTimeFromDateTime(value);
|
|
442
|
-
if (time)
|
|
443
|
-
points.add(time);
|
|
391
|
+
if (time) points.add(time);
|
|
444
392
|
}
|
|
445
393
|
addRawTimePoint(points, value) {
|
|
446
394
|
const time = this.normalizeTime(value);
|
|
447
|
-
if (time)
|
|
448
|
-
points.add(time);
|
|
395
|
+
if (time) points.add(time);
|
|
449
396
|
}
|
|
450
397
|
extractTimeFromDateTime(value) {
|
|
451
|
-
if (!value)
|
|
452
|
-
return null;
|
|
398
|
+
if (!value) return null;
|
|
453
399
|
const match = value.match(/(\d{1,2}):(\d{2})/);
|
|
454
|
-
if (!match)
|
|
455
|
-
|
|
456
|
-
return `${match[1].padStart(2, "0")}:${match[2]}`;
|
|
400
|
+
if (!match) return null;
|
|
401
|
+
return `${match[1].padStart(2, '0')}:${match[2]}`;
|
|
457
402
|
}
|
|
458
403
|
normalizeTime(value) {
|
|
459
|
-
if (!value)
|
|
460
|
-
return null;
|
|
404
|
+
if (!value) return null;
|
|
461
405
|
const match = value.match(/^(\d{1,2}):(\d{2})/);
|
|
462
|
-
if (!match)
|
|
463
|
-
|
|
464
|
-
return `${match[1].padStart(2, "0")}:${match[2]}`;
|
|
406
|
+
if (!match) return null;
|
|
407
|
+
return `${match[1].padStart(2, '0')}:${match[2]}`;
|
|
465
408
|
}
|
|
466
409
|
timeToMinutes(value) {
|
|
467
|
-
const [hour, minute] = value.split(
|
|
468
|
-
if (!Number.isFinite(hour) || !Number.isFinite(minute))
|
|
469
|
-
return 0;
|
|
410
|
+
const [hour, minute] = value.split(':').map(item => Number(item));
|
|
411
|
+
if (!Number.isFinite(hour) || !Number.isFinite(minute)) return 0;
|
|
470
412
|
return hour * 60 + minute;
|
|
471
413
|
}
|
|
472
414
|
isProductInMenuScope(product, scope) {
|
|
473
|
-
if (scope.isAllProducts)
|
|
474
|
-
|
|
475
|
-
if (!product || typeof product !== "object")
|
|
476
|
-
return false;
|
|
415
|
+
if (scope.isAllProducts) return true;
|
|
416
|
+
if (!product || typeof product !== 'object') return false;
|
|
477
417
|
const productId = this.toNumber(product.id ?? product.product_id);
|
|
478
418
|
const variantId = this.toNumber(product.product_variant_id);
|
|
479
419
|
const productKey = this.buildProductKey(productId, variantId);
|
|
480
|
-
const collectionIds = Array.isArray(product.collection_ids) ? product.collection_ids.map(
|
|
481
|
-
return collectionIds.some(
|
|
420
|
+
const collectionIds = Array.isArray(product.collection_ids) ? product.collection_ids.map(id => this.toNumber(id)) : [];
|
|
421
|
+
return collectionIds.some(id => scope.collectionIds.has(id)) || scope.productKeys.has(productKey) || scope.productAllVariantIds.has(productId);
|
|
482
422
|
}
|
|
483
423
|
mergeMatchedVariants(product, matchedVariants) {
|
|
484
|
-
const original = {
|
|
424
|
+
const original = {
|
|
425
|
+
...product
|
|
426
|
+
};
|
|
485
427
|
const sortedVariants = [...matchedVariants].sort((a, b) => {
|
|
486
|
-
if (a.priority !== b.priority)
|
|
487
|
-
return a.priority - b.priority;
|
|
428
|
+
if (a.priority !== b.priority) return a.priority - b.priority;
|
|
488
429
|
return Number(a.ruleId) - Number(b.ruleId);
|
|
489
430
|
});
|
|
490
|
-
const result = {
|
|
431
|
+
const result = {
|
|
432
|
+
...product
|
|
433
|
+
};
|
|
491
434
|
const appliedRuleIds = [];
|
|
492
|
-
const appliedFields =
|
|
435
|
+
const appliedFields = new Set();
|
|
493
436
|
for (const matched of sortedVariants) {
|
|
494
437
|
for (const [key, value] of Object.entries(matched.data)) {
|
|
495
|
-
if (value ===
|
|
496
|
-
continue;
|
|
438
|
+
if (value === undefined) continue;
|
|
497
439
|
result[key] = value;
|
|
498
440
|
appliedFields.add(key);
|
|
499
441
|
}
|
|
@@ -510,31 +452,20 @@ var DataVariantEvaluator = class {
|
|
|
510
452
|
return Array.isArray(product.data_variants) ? product.data_variants : [];
|
|
511
453
|
}
|
|
512
454
|
normalizeStrategyConfigs(configs) {
|
|
513
|
-
return configs.filter(
|
|
514
|
-
(config) => {
|
|
515
|
-
var _a;
|
|
516
|
-
return ((_a = config == null ? void 0 : config.metadata) == null ? void 0 : _a.type) === "data_variant";
|
|
517
|
-
}
|
|
518
|
-
);
|
|
455
|
+
return configs.filter(config => config?.metadata?.type === 'data_variant');
|
|
519
456
|
}
|
|
520
457
|
isStrategyActive(config) {
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
return !status || status === "active";
|
|
458
|
+
const status = config.metadata.custom?.status;
|
|
459
|
+
return !status || status === 'active';
|
|
524
460
|
}
|
|
525
461
|
getStrategyPriority(config) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
return priority;
|
|
530
|
-
return Math.max(
|
|
531
|
-
0,
|
|
532
|
-
...config.actions.map((action) => Number(action.priority || 0))
|
|
533
|
-
);
|
|
462
|
+
const priority = Number(config.metadata.custom?.priority);
|
|
463
|
+
if (Number.isFinite(priority)) return priority;
|
|
464
|
+
return Math.max(0, ...config.actions.map(action => Number(action.priority || 0)));
|
|
534
465
|
}
|
|
535
466
|
createAlwaysTrueConditions(actionIds) {
|
|
536
467
|
return {
|
|
537
|
-
operator:
|
|
468
|
+
operator: 'and',
|
|
538
469
|
rules: [],
|
|
539
470
|
actionIds
|
|
540
471
|
};
|
|
@@ -551,18 +482,16 @@ var DataVariantEvaluator = class {
|
|
|
551
482
|
return rules;
|
|
552
483
|
}
|
|
553
484
|
isConditionGroup(rule) {
|
|
554
|
-
return
|
|
485
|
+
return 'rules' in rule && Array.isArray(rule.rules);
|
|
555
486
|
}
|
|
556
487
|
normalizeNumberArray(value) {
|
|
557
|
-
if (!Array.isArray(value))
|
|
558
|
-
|
|
559
|
-
return value.map((item) => this.toNumber(item)).filter((item) => item > 0);
|
|
488
|
+
if (!Array.isArray(value)) return [];
|
|
489
|
+
return value.map(item => this.toNumber(item)).filter(item => item > 0);
|
|
560
490
|
}
|
|
561
491
|
normalizeComparableArray(value) {
|
|
562
|
-
const list = Array.isArray(value) ? value : value == null || value ===
|
|
563
|
-
const normalized = list.map(
|
|
564
|
-
if (item == null || item ===
|
|
565
|
-
return "";
|
|
492
|
+
const list = Array.isArray(value) ? value : value == null || value === '' ? [] : [value];
|
|
493
|
+
const normalized = list.map(item => {
|
|
494
|
+
if (item == null || item === '') return '';
|
|
566
495
|
const parsed = Number(item);
|
|
567
496
|
return Number.isFinite(parsed) ? String(parsed) : String(item).trim();
|
|
568
497
|
}).filter(Boolean);
|
|
@@ -575,9 +504,6 @@ var DataVariantEvaluator = class {
|
|
|
575
504
|
const parsed = Number(value);
|
|
576
505
|
return Number.isFinite(parsed) ? parsed : 0;
|
|
577
506
|
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
0 && (module.exports = {
|
|
582
|
-
DataVariantEvaluator
|
|
583
|
-
});
|
|
507
|
+
}
|
|
508
|
+
exports.DataVariantEvaluator = DataVariantEvaluator;
|
|
509
|
+
var _default = exports.default = DataVariantEvaluator;
|