@pisell/pisellos 2.1.161 → 2.1.163
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/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
- package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
- package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
- package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
- package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
- package/dist/model/strategy/adapter/dataVariant/type.d.ts +148 -0
- package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
- package/dist/model/strategy/adapter/index.d.ts +4 -0
- package/dist/model/strategy/adapter/index.js +5 -1
- package/dist/model/strategy/adapter/promotion/index.js +9 -0
- package/dist/modules/Discount/index.d.ts +5 -2
- package/dist/modules/Discount/index.js +21 -1
- package/dist/modules/Discount/types.d.ts +6 -0
- package/dist/modules/Order/index.d.ts +1 -0
- package/dist/modules/Order/index.js +18 -6
- package/dist/modules/Order/types.d.ts +2 -0
- package/dist/modules/ProductList/index.d.ts +3 -1
- package/dist/modules/ProductList/index.js +22 -11
- package/dist/modules/Rules/index.js +13 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +5 -0
- package/dist/modules/Summary/utils.js +42 -21
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/ScanOrder/index.js +1 -1
- package/dist/solution/ShopDiscount/index.js +16 -15
- package/dist/solution/VenueBooking/index.d.ts +23 -3
- package/dist/solution/VenueBooking/index.js +267 -168
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/dist/solution/VenueBooking/utils/dateSummary.js +12 -25
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -6
- package/dist/solution/VenueBooking/utils/slotMerge.js +3 -9
- package/dist/solution/VenueBooking/utils/smartPricing.d.ts +70 -0
- package/dist/solution/VenueBooking/utils/smartPricing.js +233 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +2 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +9 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -0
- package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
- package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
- package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
- package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
- package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
- package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
- package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
- package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
- package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
- package/lib/model/strategy/adapter/index.d.ts +4 -0
- package/lib/model/strategy/adapter/index.js +13 -2
- package/lib/modules/Discount/index.d.ts +5 -2
- package/lib/modules/Discount/index.js +11 -1
- package/lib/modules/Discount/types.d.ts +6 -0
- package/lib/modules/Order/index.d.ts +1 -0
- package/lib/modules/Order/index.js +11 -1
- package/lib/modules/Order/types.d.ts +2 -0
- package/lib/modules/ProductList/index.d.ts +3 -1
- package/lib/modules/ProductList/index.js +45 -39
- package/lib/modules/Rules/index.js +8 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +4 -0
- package/lib/modules/Summary/utils.js +23 -3
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/ScanOrder/index.js +1 -1
- package/lib/solution/ShopDiscount/index.js +3 -2
- package/lib/solution/VenueBooking/index.d.ts +23 -3
- package/lib/solution/VenueBooking/index.js +164 -69
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +2 -2
- package/lib/solution/VenueBooking/utils/dateSummary.js +5 -10
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -6
- package/lib/solution/VenueBooking/utils/slotMerge.js +3 -4
- package/lib/solution/VenueBooking/utils/smartPricing.d.ts +70 -0
- package/lib/solution/VenueBooking/utils/smartPricing.js +180 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +2 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +7 -3
- package/package.json +1 -1
|
@@ -50,6 +50,7 @@ var import_resource = require("./utils/resource");
|
|
|
50
50
|
var import_timeSlot = require("./utils/timeSlot");
|
|
51
51
|
var import_dateSummary = require("./utils/dateSummary");
|
|
52
52
|
var import_slotMerge = require("./utils/slotMerge");
|
|
53
|
+
var import_smartPricing = require("./utils/smartPricing");
|
|
53
54
|
var import_utils3 = require("../../modules/Order/utils");
|
|
54
55
|
var import_Order = require("../../modules/Order");
|
|
55
56
|
var import_types4 = require("../RegisterAndLogin/types");
|
|
@@ -110,6 +111,10 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
110
111
|
this.loadAllProductsInFlight = null;
|
|
111
112
|
this.productsLoaded = false;
|
|
112
113
|
this.loadOpenDataConfigInFlight = null;
|
|
114
|
+
/** 按日期缓存 slot 智能定价 Map,避免同周重复 resolveProducts */
|
|
115
|
+
this.slotPriceMapCache = /* @__PURE__ */ new Map();
|
|
116
|
+
/** loadProducts 后缓存的全量商品(venue + addon),供分段算价复用 */
|
|
117
|
+
this.smartPricingProductCatalog = [];
|
|
113
118
|
}
|
|
114
119
|
getLoggerContext() {
|
|
115
120
|
return {
|
|
@@ -298,16 +303,11 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
298
303
|
}
|
|
299
304
|
this.customerLoginRefreshIdInFlight = params.customerId;
|
|
300
305
|
const refreshTask = (async () => {
|
|
301
|
-
var _a;
|
|
302
|
-
if (this.store.quotation) {
|
|
303
|
-
await this.store.quotation.loadQuotations({
|
|
304
|
-
channel: (_a = this.otherParams) == null ? void 0 : _a.channel
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
this.recalculateOrderPricesFromQuotation();
|
|
308
306
|
await this.store.order.loadDiscountConfig({
|
|
309
307
|
customerId: params.customerId
|
|
310
308
|
});
|
|
309
|
+
this.clearSlotPriceMapCache();
|
|
310
|
+
this.recalculateOrderPricesFromSmartPricing();
|
|
311
311
|
await this.store.order.recalculateSummary({ createIfMissing: true });
|
|
312
312
|
this.store.order.persistTempOrder();
|
|
313
313
|
await this.refreshItemRuleQuantityLimits();
|
|
@@ -326,7 +326,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
async initialize(core, options = {}) {
|
|
329
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
329
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
330
330
|
this.logMethodStart("initialize");
|
|
331
331
|
this.core = core;
|
|
332
332
|
this.initializeOptions = options || {};
|
|
@@ -462,10 +462,6 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
462
462
|
await this.loadRuntimeConfigs();
|
|
463
463
|
if (this.store.schedule) {
|
|
464
464
|
await this.store.schedule.loadAllSchedule();
|
|
465
|
-
this.injectScheduleResolverToQuotation();
|
|
466
|
-
(_k = this.store.quotation) == null ? void 0 : _k.loadQuotations({
|
|
467
|
-
channel: (_j = this.otherParams) == null ? void 0 : _j.channel
|
|
468
|
-
});
|
|
469
465
|
}
|
|
470
466
|
await this.refreshItemRuleQuantityLimits();
|
|
471
467
|
this.store.status = "ready";
|
|
@@ -541,6 +537,93 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
541
537
|
getCartValidation() {
|
|
542
538
|
return this.store.cartValidation || { passed: null, failures: [] };
|
|
543
539
|
}
|
|
540
|
+
/** 清除 slot 价格分段缓存(商品重载 / 登录后 customerId 变化时调用) */
|
|
541
|
+
clearSlotPriceMapCache() {
|
|
542
|
+
this.slotPriceMapCache.clear();
|
|
543
|
+
}
|
|
544
|
+
/** 读取当前登录 customerId */
|
|
545
|
+
resolveCustomerIdForSmartPricing() {
|
|
546
|
+
var _a, _b, _c;
|
|
547
|
+
try {
|
|
548
|
+
const userPlugin = (_a = this.core) == null ? void 0 : _a.getPlugin("user");
|
|
549
|
+
const customerId = Number((_c = (_b = userPlugin == null ? void 0 : userPlugin.get) == null ? void 0 : _b.call(userPlugin)) == null ? void 0 : _c.id);
|
|
550
|
+
return Number.isFinite(customerId) && customerId > 0 ? customerId : void 0;
|
|
551
|
+
} catch {
|
|
552
|
+
return void 0;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
resolveAvailableWalletIdsForSmartPricing() {
|
|
556
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
557
|
+
const orderWalletIds = (_b = (_a = this.store.order) == null ? void 0 : _a.getAvailableWalletIds) == null ? void 0 : _b.call(_a);
|
|
558
|
+
const fallbackWalletIds = ((_c = this.otherParams) == null ? void 0 : _c.available_wallet_ids) || ((_d = this.otherParams) == null ? void 0 : _d.availableWalletIds) || ((_f = (_e = this.otherParams) == null ? void 0 : _e.strategy_context) == null ? void 0 : _f.available_wallet_ids) || ((_h = (_g = this.otherParams) == null ? void 0 : _g.strategy_context) == null ? void 0 : _h.availableWalletIds);
|
|
559
|
+
const source = Array.isArray(orderWalletIds) && orderWalletIds.length ? orderWalletIds : fallbackWalletIds;
|
|
560
|
+
if (!Array.isArray(source))
|
|
561
|
+
return [];
|
|
562
|
+
const ids = source.map((item) => Number(item)).filter((item) => Number.isFinite(item) && item > 0);
|
|
563
|
+
return Array.from(new Set(ids));
|
|
564
|
+
}
|
|
565
|
+
/** 读取 schedule 全量列表,供智能定价 schedule_match 使用 */
|
|
566
|
+
getScheduleListForSmartPricing() {
|
|
567
|
+
var _a;
|
|
568
|
+
const scheduleModule = this.store.schedule;
|
|
569
|
+
const list = (_a = scheduleModule == null ? void 0 : scheduleModule.store) == null ? void 0 : _a.scheduleList;
|
|
570
|
+
return Array.isArray(list) ? list : [];
|
|
571
|
+
}
|
|
572
|
+
/** 构建智能定价上下文,对齐 OS Server buildProductFormatterContext */
|
|
573
|
+
buildSmartPricingContext(customerId) {
|
|
574
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
575
|
+
const evaluator = (_b = (_a = this.core) == null ? void 0 : _a.context) == null ? void 0 : _b.dataVariantEvaluator;
|
|
576
|
+
return {
|
|
577
|
+
evaluator,
|
|
578
|
+
scheduleList: this.getScheduleListForSmartPricing(),
|
|
579
|
+
menuList: ((_c = this.otherParams) == null ? void 0 : _c.menuList) || ((_e = (_d = this.otherParams) == null ? void 0 : _d.openData) == null ? void 0 : _e.menuList) || [],
|
|
580
|
+
customerId: customerId ?? this.resolveCustomerIdForSmartPricing(),
|
|
581
|
+
availableWalletIds: this.resolveAvailableWalletIdsForSmartPricing(),
|
|
582
|
+
channel: (_f = this.otherParams) == null ? void 0 : _f.channel,
|
|
583
|
+
businessCode: (_g = this.otherParams) == null ? void 0 : _g.businessCode,
|
|
584
|
+
orderType: ((_h = this.otherParams) == null ? void 0 : _h.orderType) || ((_i = this.otherParams) == null ? void 0 : _i.type),
|
|
585
|
+
strategy_context: (_j = this.otherParams) == null ? void 0 : _j.strategy_context
|
|
586
|
+
};
|
|
587
|
+
}
|
|
588
|
+
/** venue + addon 全量商品,供智能定价评估 */
|
|
589
|
+
getAllProductsForSmartPricing() {
|
|
590
|
+
if (this.smartPricingProductCatalog.length) {
|
|
591
|
+
return this.smartPricingProductCatalog;
|
|
592
|
+
}
|
|
593
|
+
const venueList = this.getVenueProducts();
|
|
594
|
+
const addonList = this.getAddonProductsList();
|
|
595
|
+
return [...venueList, ...addonList];
|
|
596
|
+
}
|
|
597
|
+
getSlotPriceMapCacheKey(date, context) {
|
|
598
|
+
return [
|
|
599
|
+
date,
|
|
600
|
+
context.customerId ?? "",
|
|
601
|
+
(context.availableWalletIds || []).join(","),
|
|
602
|
+
context.channel ?? "",
|
|
603
|
+
context.businessCode ?? ""
|
|
604
|
+
].join("|");
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* 按 schedule 分段构建 slot 价格 Map,带实例级缓存。
|
|
608
|
+
*/
|
|
609
|
+
buildSlotPriceMapForDate(date, config, productIds) {
|
|
610
|
+
const context = this.buildSmartPricingContext();
|
|
611
|
+
const cacheKey = this.getSlotPriceMapCacheKey(date, context);
|
|
612
|
+
const cached = this.slotPriceMapCache.get(cacheKey);
|
|
613
|
+
if (cached)
|
|
614
|
+
return cached;
|
|
615
|
+
const timeLabels = (0, import_timeSlot.generateTimeLabels)(config);
|
|
616
|
+
const slotPriceMap = (0, import_smartPricing.buildSlotPriceMapByScheduleSegments)({
|
|
617
|
+
products: this.getAllProductsForSmartPricing(),
|
|
618
|
+
productIds,
|
|
619
|
+
date,
|
|
620
|
+
timeLabels,
|
|
621
|
+
config,
|
|
622
|
+
context
|
|
623
|
+
});
|
|
624
|
+
this.slotPriceMapCache.set(cacheKey, slotPriceMap);
|
|
625
|
+
return slotPriceMap;
|
|
626
|
+
}
|
|
544
627
|
// ─── 场地商品 & 附加商品 ───
|
|
545
628
|
async loadAllProducts() {
|
|
546
629
|
if (this.loadAllProductsInFlight)
|
|
@@ -569,9 +652,18 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
569
652
|
menu_list_ids: menuListIds,
|
|
570
653
|
cacheId: this.cacheId,
|
|
571
654
|
schedule_date: (0, import_dayjs.default)().format("YYYY-MM-DD"),
|
|
572
|
-
schedule_datetime: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
|
|
655
|
+
schedule_datetime: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
|
|
656
|
+
with_extra: ["dataVariants"]
|
|
573
657
|
});
|
|
574
|
-
const
|
|
658
|
+
const rawList = Array.isArray(allProducts) ? allProducts : [];
|
|
659
|
+
let list = rawList;
|
|
660
|
+
this.smartPricingProductCatalog = rawList.slice();
|
|
661
|
+
list = (0, import_smartPricing.formatProductsWithDataVariant)(
|
|
662
|
+
list,
|
|
663
|
+
this.buildSmartPricingContext(),
|
|
664
|
+
(0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
|
|
665
|
+
);
|
|
666
|
+
this.clearSlotPriceMapCache();
|
|
575
667
|
const venueList = list.filter((p) => p.duration != null);
|
|
576
668
|
const addonList = list.filter((p) => p.duration == null);
|
|
577
669
|
const venueStore = (_c = this.store.venueProducts) == null ? void 0 : _c.store;
|
|
@@ -752,29 +844,24 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
752
844
|
config: this.baseSlotConfig,
|
|
753
845
|
rawResources: this.store.rawResourceData,
|
|
754
846
|
resourceProductMap: this.resourceProductMap,
|
|
755
|
-
|
|
756
|
-
|
|
847
|
+
resolveConfig: (date) => this.resolveSlotConfigForDate(date),
|
|
848
|
+
buildSlotPriceMap: (date, config, productIds) => this.buildSlotPriceMapForDate(date, config, productIds)
|
|
757
849
|
});
|
|
758
850
|
}
|
|
759
851
|
getTimeSlotGrid(date) {
|
|
760
852
|
const resolvedSlotConfig = this.syncOperatingHoursToSlotConfig(date);
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
];
|
|
768
|
-
const timeLabels = (0, import_timeSlot.generateTimeLabels)(resolvedSlotConfig);
|
|
769
|
-
const timePoints = timeLabels.map((label) => `${date} ${label}`);
|
|
770
|
-
quotationPriceMap = this.store.quotation.buildProductPriceMap({ productIds, timePoints });
|
|
771
|
-
}
|
|
853
|
+
const productIds = [
|
|
854
|
+
...new Set(
|
|
855
|
+
[...this.resourceProductMap.values()].flat().map((m) => m.productId)
|
|
856
|
+
)
|
|
857
|
+
];
|
|
858
|
+
const slotPriceMap = productIds.length ? this.buildSlotPriceMapForDate(date, resolvedSlotConfig, productIds) : void 0;
|
|
772
859
|
return (0, import_timeSlot.buildTimeSlotGrid)({
|
|
773
860
|
date,
|
|
774
861
|
config: resolvedSlotConfig,
|
|
775
862
|
rawResources: this.store.rawResourceData,
|
|
776
863
|
resourceProductMap: this.resourceProductMap,
|
|
777
|
-
|
|
864
|
+
slotPriceMap
|
|
778
865
|
});
|
|
779
866
|
}
|
|
780
867
|
// ─── 时间槽订单操作 ───
|
|
@@ -1059,8 +1146,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
1059
1146
|
booking_uid: bookingUuid,
|
|
1060
1147
|
price_breakdown: (0, import_slotMerge.buildPriceBreakdown)({
|
|
1061
1148
|
group,
|
|
1062
|
-
productId: mapping.productId
|
|
1063
|
-
quotation: this.store.quotation
|
|
1149
|
+
productId: mapping.productId
|
|
1064
1150
|
})
|
|
1065
1151
|
},
|
|
1066
1152
|
_origin: {
|
|
@@ -1153,20 +1239,12 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
1153
1239
|
if (!this.store.schedule)
|
|
1154
1240
|
throw new Error("schedule 模块未初始化");
|
|
1155
1241
|
await this.store.schedule.loadAllSchedule();
|
|
1156
|
-
this.injectScheduleResolverToQuotation();
|
|
1157
1242
|
this.logMethodSuccess("loadSchedules");
|
|
1158
1243
|
} catch (error) {
|
|
1159
1244
|
this.logMethodError("loadSchedules", error);
|
|
1160
1245
|
throw error;
|
|
1161
1246
|
}
|
|
1162
1247
|
}
|
|
1163
|
-
injectScheduleResolverToQuotation() {
|
|
1164
|
-
if (this.store.quotation && this.store.schedule) {
|
|
1165
|
-
this.store.quotation.setScheduleResolver(
|
|
1166
|
-
(id) => this.store.schedule.getScheduleListByIds([id])[0]
|
|
1167
|
-
);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
1248
|
getScheduleListByIds(ids) {
|
|
1171
1249
|
if (!this.store.schedule)
|
|
1172
1250
|
return [];
|
|
@@ -1205,14 +1283,16 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
1205
1283
|
throw error;
|
|
1206
1284
|
}
|
|
1207
1285
|
}
|
|
1208
|
-
|
|
1286
|
+
recalculateOrderPricesFromSmartPricing() {
|
|
1209
1287
|
var _a, _b;
|
|
1210
|
-
if (!this.store.order
|
|
1288
|
+
if (!this.store.order)
|
|
1211
1289
|
return;
|
|
1212
1290
|
const tempOrder = this.store.order.getTempOrder();
|
|
1213
1291
|
if (!((_a = tempOrder == null ? void 0 : tempOrder.products) == null ? void 0 : _a.length))
|
|
1214
1292
|
return;
|
|
1215
1293
|
const now = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
|
|
1294
|
+
const catalog = this.getAllProductsForSmartPricing();
|
|
1295
|
+
const context = this.buildSmartPricingContext();
|
|
1216
1296
|
for (const product of tempOrder.products) {
|
|
1217
1297
|
if ((_b = product.metadata) == null ? void 0 : _b.venue_booking) {
|
|
1218
1298
|
const mappings = this.resourceProductMap.get(product.metadata.resource_id);
|
|
@@ -1225,34 +1305,49 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
1225
1305
|
product,
|
|
1226
1306
|
this.store.slotConfig.slotDurationMinutes
|
|
1227
1307
|
);
|
|
1228
|
-
const
|
|
1229
|
-
...slot,
|
|
1230
|
-
|
|
1231
|
-
|
|
1308
|
+
const uniqueDates = [
|
|
1309
|
+
...new Set(slots.map((slot) => (0, import_dayjs.default)(slot.startTime).format("YYYY-MM-DD")))
|
|
1310
|
+
];
|
|
1311
|
+
const slotPriceMaps = /* @__PURE__ */ new Map();
|
|
1312
|
+
for (const slotDate of uniqueDates) {
|
|
1313
|
+
slotPriceMaps.set(
|
|
1314
|
+
slotDate,
|
|
1315
|
+
this.buildSlotPriceMapForDate(slotDate, this.store.slotConfig, [mapping.productId])
|
|
1316
|
+
);
|
|
1317
|
+
}
|
|
1318
|
+
const updatedSlots = slots.map((slot) => {
|
|
1319
|
+
const slotDate = (0, import_dayjs.default)(slot.startTime).format("YYYY-MM-DD");
|
|
1320
|
+
const slotPriceMap = slotPriceMaps.get(slotDate);
|
|
1321
|
+
return {
|
|
1322
|
+
...slot,
|
|
1232
1323
|
productId: mapping.productId,
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1324
|
+
price: slotPriceMap ? (0, import_smartPricing.getSlotPriceFromMap)({
|
|
1325
|
+
slotPriceMap,
|
|
1326
|
+
productId: mapping.productId,
|
|
1327
|
+
slotStartTime: slot.startTime,
|
|
1328
|
+
fallbackPrice: mapping.price
|
|
1329
|
+
}) : mapping.price
|
|
1330
|
+
};
|
|
1331
|
+
});
|
|
1236
1332
|
const merged = (0, import_slotMerge.mergeConsecutiveSlots)(updatedSlots);
|
|
1237
1333
|
if (merged.length === 1) {
|
|
1238
1334
|
product.selling_price = merged[0].totalPrice;
|
|
1239
1335
|
product.original_price = merged[0].totalPrice;
|
|
1240
1336
|
product.metadata.price_breakdown = (0, import_slotMerge.buildPriceBreakdown)({
|
|
1241
1337
|
group: merged[0],
|
|
1242
|
-
productId: mapping.productId
|
|
1243
|
-
quotation: this.store.quotation
|
|
1338
|
+
productId: mapping.productId
|
|
1244
1339
|
});
|
|
1245
1340
|
}
|
|
1246
1341
|
} else if (product.product_id != null) {
|
|
1247
|
-
const
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1342
|
+
const smartPrice = (0, import_smartPricing.getPriceForProductAtDatetime)({
|
|
1343
|
+
products: catalog,
|
|
1344
|
+
context,
|
|
1345
|
+
productId: Number(product.product_id),
|
|
1346
|
+
datetime: now,
|
|
1347
|
+
fallbackPrice: product.selling_price
|
|
1251
1348
|
});
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
product.original_price = quotationPrice;
|
|
1255
|
-
}
|
|
1349
|
+
product.selling_price = smartPrice;
|
|
1350
|
+
product.original_price = smartPrice;
|
|
1256
1351
|
}
|
|
1257
1352
|
}
|
|
1258
1353
|
}
|
|
@@ -1438,7 +1533,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
1438
1533
|
}
|
|
1439
1534
|
}
|
|
1440
1535
|
async addProductToOrder(product) {
|
|
1441
|
-
var _a;
|
|
1536
|
+
var _a, _b;
|
|
1442
1537
|
this.logMethodStart("addProductToOrder", {
|
|
1443
1538
|
product_id: product.product_id,
|
|
1444
1539
|
product_variant_id: product.product_variant_id
|
|
@@ -1446,18 +1541,18 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
|
|
|
1446
1541
|
try {
|
|
1447
1542
|
if (!this.store.order)
|
|
1448
1543
|
throw new Error("order 模块未初始化");
|
|
1449
|
-
if (!((_a = product.metadata) == null ? void 0 : _a.venue_booking) &&
|
|
1450
|
-
const
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1544
|
+
if (!((_a = product.metadata) == null ? void 0 : _a.venue_booking) && product.product_id != null) {
|
|
1545
|
+
const smartPrice = (0, import_smartPricing.getPriceForProductAtDatetime)({
|
|
1546
|
+
products: this.getAllProductsForSmartPricing(),
|
|
1547
|
+
context: this.buildSmartPricingContext(),
|
|
1548
|
+
productId: Number(product.product_id),
|
|
1549
|
+
datetime: (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss"),
|
|
1550
|
+
fallbackPrice: product.selling_price
|
|
1454
1551
|
});
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
product.original_price = product.selling_price;
|
|
1460
|
-
}
|
|
1552
|
+
product.selling_price = smartPrice;
|
|
1553
|
+
product.original_price = smartPrice;
|
|
1554
|
+
} else if (product.selling_price != null && !((_b = product.metadata) == null ? void 0 : _b.venue_booking)) {
|
|
1555
|
+
product.original_price = product.selling_price;
|
|
1461
1556
|
}
|
|
1462
1557
|
const products = await this.store.order.addProductToOrder(product);
|
|
1463
1558
|
await this.refreshItemRuleQuantityLimits();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { VenueBookingSlotConfig, VenueResourceRawData, VenueDateSummaryItem, ResourceProductMapping } from '../types';
|
|
2
|
-
import type { QuotationModule } from '../../../modules/Quotation';
|
|
3
2
|
export declare function buildDateRangeSummary(params: {
|
|
4
3
|
startDate: string;
|
|
5
4
|
endDate: string;
|
|
6
5
|
config: VenueBookingSlotConfig;
|
|
7
6
|
rawResources: VenueResourceRawData[];
|
|
8
7
|
resourceProductMap: Map<number | string, ResourceProductMapping[]>;
|
|
9
|
-
quotationModule?: QuotationModule;
|
|
10
8
|
resolveConfig?: (date: string) => VenueBookingSlotConfig;
|
|
9
|
+
/** 按日期构建 slot 智能定价 Map */
|
|
10
|
+
buildSlotPriceMap?: (date: string, config: VenueBookingSlotConfig, productIds: number[]) => Map<string, string | null>;
|
|
11
11
|
}): VenueDateSummaryItem[];
|
|
@@ -41,28 +41,23 @@ function buildDateRangeSummary(params) {
|
|
|
41
41
|
config,
|
|
42
42
|
rawResources,
|
|
43
43
|
resourceProductMap,
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
resolveConfig,
|
|
45
|
+
buildSlotPriceMap
|
|
46
46
|
} = params;
|
|
47
47
|
const result = [];
|
|
48
|
-
const productIds =
|
|
48
|
+
const productIds = buildSlotPriceMap ? [...new Set([...resourceProductMap.values()].flat().map((m) => m.productId))] : [];
|
|
49
49
|
let cursor = (0, import_dayjs.default)(startDate);
|
|
50
50
|
const end = (0, import_dayjs.default)(endDate);
|
|
51
51
|
while (!cursor.isAfter(end)) {
|
|
52
52
|
const date = cursor.format("YYYY-MM-DD");
|
|
53
53
|
const effectiveConfig = (resolveConfig == null ? void 0 : resolveConfig(date)) || config;
|
|
54
|
-
|
|
55
|
-
if (quotationModule && productIds.length) {
|
|
56
|
-
const timeLabels = (0, import_timeSlot.generateTimeLabels)(effectiveConfig);
|
|
57
|
-
const timePoints = timeLabels.map((label) => `${date} ${label}`);
|
|
58
|
-
quotationPriceMap = quotationModule.buildProductPriceMap({ productIds, timePoints });
|
|
59
|
-
}
|
|
54
|
+
const slotPriceMap = buildSlotPriceMap && productIds.length ? buildSlotPriceMap(date, effectiveConfig, productIds) : void 0;
|
|
60
55
|
const grid = (0, import_timeSlot.buildTimeSlotGrid)({
|
|
61
56
|
date,
|
|
62
57
|
config: effectiveConfig,
|
|
63
58
|
rawResources,
|
|
64
59
|
resourceProductMap,
|
|
65
|
-
|
|
60
|
+
slotPriceMap
|
|
66
61
|
});
|
|
67
62
|
let totalSlots = 0;
|
|
68
63
|
let availableSlots = 0;
|
|
@@ -5,12 +5,6 @@ export declare function mergeConsecutiveSlots(slots: VenueSlotSelection[]): Merg
|
|
|
5
5
|
export declare function buildPriceBreakdown(params: {
|
|
6
6
|
group: MergedSlotGroup;
|
|
7
7
|
productId: number;
|
|
8
|
-
quotation?: {
|
|
9
|
-
getQuotationShelfId: (p: {
|
|
10
|
-
productId: number;
|
|
11
|
-
datetime: string;
|
|
12
|
-
}) => number;
|
|
13
|
-
};
|
|
14
8
|
}): PriceBreakdownEntry[];
|
|
15
9
|
export interface BuildVenueBookingParams {
|
|
16
10
|
group: MergedSlotGroup;
|
|
@@ -82,17 +82,16 @@ function mergeConsecutiveSlots(slots) {
|
|
|
82
82
|
return groups;
|
|
83
83
|
}
|
|
84
84
|
function buildPriceBreakdown(params) {
|
|
85
|
-
const { group
|
|
85
|
+
const { group } = params;
|
|
86
86
|
if (!group.slots.length)
|
|
87
87
|
return [];
|
|
88
88
|
const entries = [];
|
|
89
89
|
for (const slot of group.slots) {
|
|
90
90
|
const unitPrice = Number(slot.price || "0");
|
|
91
|
-
const shelfId = quotation ? quotation.getQuotationShelfId({ productId, datetime: slot.startTime }) : 0;
|
|
92
91
|
const startHm = (0, import_dayjs.default)(slot.startTime, "YYYY-MM-DD HH:mm").format("YYYY-MM-DD HH:mm");
|
|
93
92
|
const endHm = (0, import_dayjs.default)(slot.endTime, "YYYY-MM-DD HH:mm").format("YYYY-MM-DD HH:mm");
|
|
94
93
|
const last = entries[entries.length - 1];
|
|
95
|
-
if (last && last.unit_price === unitPrice && last.quotation_shelf_id ===
|
|
94
|
+
if (last && last.unit_price === unitPrice && last.quotation_shelf_id === 0 && last.end_time === startHm) {
|
|
96
95
|
last.end_time = endHm;
|
|
97
96
|
last.quantity += 1;
|
|
98
97
|
} else {
|
|
@@ -100,7 +99,7 @@ function buildPriceBreakdown(params) {
|
|
|
100
99
|
start_time: startHm,
|
|
101
100
|
end_time: endHm,
|
|
102
101
|
unit_price: unitPrice,
|
|
103
|
-
quotation_shelf_id:
|
|
102
|
+
quotation_shelf_id: 0,
|
|
104
103
|
quantity: 1
|
|
105
104
|
});
|
|
106
105
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ProductData } from '../../../modules/Product/types';
|
|
2
|
+
import type { ScheduleItem } from '../../../modules/Schedule/types';
|
|
3
|
+
import type { DataVariantBusinessData, DataVariantMenu, DataVariantProduct } from '../../../model/strategy/adapter/dataVariant/type';
|
|
4
|
+
import type { DataVariantEvaluator } from '../../../model/strategy/adapter/dataVariant/evaluator';
|
|
5
|
+
import type { StrategyConfig } from '../../../model/strategy/type';
|
|
6
|
+
import type { VenueBookingSlotConfig } from '../types';
|
|
7
|
+
/** VenueBooking 智能定价运行时上下文 */
|
|
8
|
+
export interface VenueBookingSmartPricingContext {
|
|
9
|
+
evaluator?: DataVariantEvaluator | null;
|
|
10
|
+
scheduleList?: ScheduleItem[];
|
|
11
|
+
menuList?: DataVariantMenu[];
|
|
12
|
+
customerId?: number | string;
|
|
13
|
+
availableWalletIds?: Array<number | string>;
|
|
14
|
+
channel?: string;
|
|
15
|
+
businessCode?: string;
|
|
16
|
+
orderType?: string;
|
|
17
|
+
strategy_context?: Record<string, any>;
|
|
18
|
+
strategyConfigs?: StrategyConfig[];
|
|
19
|
+
}
|
|
20
|
+
/** 从商品上读取展示/算价用的 price 字段 */
|
|
21
|
+
export declare function extractProductPrice(product: DataVariantProduct): string | null;
|
|
22
|
+
/** 组装 DataVariant 评估入参,对齐 OS Server buildProductFormatterContext 语义 */
|
|
23
|
+
export declare function buildDataVariantBusinessData(products: ProductData[], context: VenueBookingSmartPricingContext, scheduleDateTime: string): DataVariantBusinessData;
|
|
24
|
+
/**
|
|
25
|
+
* 对商品列表执行一次智能定价格式化(loadProducts 后使用)。
|
|
26
|
+
* evaluator 未注入时原样返回并打 warning。
|
|
27
|
+
*/
|
|
28
|
+
export declare function formatProductsWithDataVariant(products: ProductData[], context: VenueBookingSmartPricingContext, scheduleDateTime?: string): ProductData[];
|
|
29
|
+
/**
|
|
30
|
+
* 根据 schedule_time_points 与营业开始时间,构造当天需要评估的 datetime 列表(升序)。
|
|
31
|
+
* 跨日营业时,早于营业开始小时的时间点归到次日。
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildEvaluationDatetimes(params: {
|
|
34
|
+
date: string;
|
|
35
|
+
config: VenueBookingSlotConfig;
|
|
36
|
+
scheduleTimePoints: string[];
|
|
37
|
+
}): string[];
|
|
38
|
+
/** 找到 slot 时间所属分段的评估 datetime(max(evalDt <= slotDt)) */
|
|
39
|
+
export declare function findSegmentEvalDatetime(slotDatetime: string, evalDatetimes: string[]): string;
|
|
40
|
+
/** 将 slot 标签转为与 timeSlot 网格一致的 slotStart 字符串 */
|
|
41
|
+
export declare function buildSlotStartDatetime(date: string, label: string, config: VenueBookingSlotConfig): string;
|
|
42
|
+
/**
|
|
43
|
+
* 按 schedule 分段批量 resolveProducts,输出与 quotation 相同 key 格式的 slot 价格 Map。
|
|
44
|
+
* key: `${productId}:${slotStart}`,value: price | null
|
|
45
|
+
*/
|
|
46
|
+
export declare function buildSlotPriceMapByScheduleSegments(params: {
|
|
47
|
+
products: ProductData[];
|
|
48
|
+
productIds: number[];
|
|
49
|
+
date: string;
|
|
50
|
+
timeLabels: string[];
|
|
51
|
+
config: VenueBookingSlotConfig;
|
|
52
|
+
context: VenueBookingSmartPricingContext;
|
|
53
|
+
}): Map<string, string | null>;
|
|
54
|
+
/**
|
|
55
|
+
* 指定商品在某一 datetime 的智能定价(addon / 单点重算用)。
|
|
56
|
+
*/
|
|
57
|
+
export declare function getPriceForProductAtDatetime(params: {
|
|
58
|
+
products: ProductData[];
|
|
59
|
+
context: VenueBookingSmartPricingContext;
|
|
60
|
+
productId: number;
|
|
61
|
+
datetime: string;
|
|
62
|
+
fallbackPrice?: string;
|
|
63
|
+
}): string;
|
|
64
|
+
/** 从 slot 价格 Map 读取单价,找不到则回退 fallback */
|
|
65
|
+
export declare function getSlotPriceFromMap(params: {
|
|
66
|
+
slotPriceMap: Map<string, string | null>;
|
|
67
|
+
productId: number;
|
|
68
|
+
slotStartTime: string;
|
|
69
|
+
fallbackPrice?: string;
|
|
70
|
+
}): string;
|