@pisell/pisellos 0.10.81 → 0.10.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +5 -0
- package/dist/modules/ResourcePlanner/planner.js +2 -1
- package/dist/solution/BookingByStep/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.d.ts +1 -13
- package/dist/solution/BookingTicket/index.js +36 -31
- package/dist/solution/ScanOrder/index.d.ts +0 -1
- package/dist/solution/ScanOrder/index.js +62 -59
- package/dist/solution/ScanOrder/types.d.ts +2 -0
- package/dist/solution/ScanOrder/types.js +2 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +12 -1
- package/dist/solution/UnifiedBookingSales/index.js +1471 -1143
- package/dist/solution/UnifiedBookingSales/types.d.ts +6 -0
- package/dist/solution/VenueBooking/index.js +111 -104
- package/dist/solution/VenueBooking/types.d.ts +2 -0
- package/dist/solution/VenueBooking/types.js +3 -1
- package/dist/solution/VenueBooking/utils/smartPricing.d.ts +1 -0
- package/dist/solution/VenueBooking/utils/smartPricing.js +6 -1
- package/dist/utils/hostLogger.d.ts +10 -0
- package/dist/utils/hostLogger.js +20 -0
- package/lib/model/strategy/adapter/promotion/index.js +46 -1
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +5 -0
- package/lib/modules/ResourcePlanner/planner.js +2 -1
- package/lib/solution/BookingByStep/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.d.ts +1 -13
- package/lib/solution/BookingTicket/index.js +5 -4
- package/lib/solution/ScanOrder/index.d.ts +0 -1
- package/lib/solution/ScanOrder/index.js +47 -41
- package/lib/solution/ScanOrder/types.d.ts +2 -0
- package/lib/solution/ScanOrder/types.js +1 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +12 -1
- package/lib/solution/UnifiedBookingSales/index.js +249 -29
- package/lib/solution/UnifiedBookingSales/types.d.ts +6 -0
- package/lib/solution/VenueBooking/index.js +38 -47
- package/lib/solution/VenueBooking/types.d.ts +2 -0
- package/lib/solution/VenueBooking/types.js +3 -1
- package/lib/solution/VenueBooking/utils/smartPricing.d.ts +1 -0
- package/lib/solution/VenueBooking/utils/smartPricing.js +6 -1
- package/lib/utils/hostLogger.d.ts +10 -0
- package/lib/utils/hostLogger.js +25 -0
- package/package.json +1 -1
|
@@ -71,6 +71,7 @@ var _BookingTicket = require("../BookingTicket");
|
|
|
71
71
|
var _localClock = require("../../modules/ResourcePlanner/localClock");
|
|
72
72
|
var _platform = require("../../utils/platform");
|
|
73
73
|
var _itemRule = require("../../model/strategy/adapter/itemRule");
|
|
74
|
+
var _hostLogger = require("../../utils/hostLogger");
|
|
74
75
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
75
76
|
const OPEN_DATA_SECTION_CODES = ['sale', 'reservation', 'fulfillment', 'menu', 'workflow', 'documents', 'basic', 'checkout', 'availability', 'interface'];
|
|
76
77
|
function normalizePositiveInteger(value) {
|
|
@@ -1171,6 +1172,12 @@ function buildPosForcedAvailabilityAssignments(params) {
|
|
|
1171
1172
|
}
|
|
1172
1173
|
selectedResourceIds.forEach(resourceId => {
|
|
1173
1174
|
if (sameAvailabilityId(resourceId, POS_NO_RESOURCE_ID)) {
|
|
1175
|
+
if (params.allowNoResource === false) {
|
|
1176
|
+
addConflict('resource_unavailable', '必须选择当前商品的有效资源', {
|
|
1177
|
+
resourceId
|
|
1178
|
+
});
|
|
1179
|
+
return;
|
|
1180
|
+
}
|
|
1174
1181
|
assignments.push({
|
|
1175
1182
|
productId: product.id,
|
|
1176
1183
|
resourceId: POS_NO_RESOURCE_ID,
|
|
@@ -1217,6 +1224,45 @@ function buildPosForcedAvailabilityAssignments(params) {
|
|
|
1217
1224
|
conflicts
|
|
1218
1225
|
};
|
|
1219
1226
|
}
|
|
1227
|
+
|
|
1228
|
+
/** Structural conversion only. The customer has already picked a time and resources in the UI. */
|
|
1229
|
+
function acceptCustomerSelectionSnapshot(params) {
|
|
1230
|
+
const {
|
|
1231
|
+
candidate
|
|
1232
|
+
} = params;
|
|
1233
|
+
try {
|
|
1234
|
+
const start = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(candidate.startAt));
|
|
1235
|
+
const end = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(candidate.endAt));
|
|
1236
|
+
const bookingStart = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(candidate.bookingStartAt));
|
|
1237
|
+
const bookingEnd = (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(candidate.bookingEndAt));
|
|
1238
|
+
if (end <= start || bookingEnd <= bookingStart) throw new Error('invalid interval');
|
|
1239
|
+
} catch {
|
|
1240
|
+
throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', '所选时间必须是有效且递增的区间');
|
|
1241
|
+
}
|
|
1242
|
+
const {
|
|
1243
|
+
assignments,
|
|
1244
|
+
conflicts
|
|
1245
|
+
} = buildPosForcedAvailabilityAssignments({
|
|
1246
|
+
...params,
|
|
1247
|
+
allowNoResource: false
|
|
1248
|
+
});
|
|
1249
|
+
// Preserve the original time-card snapshot for callers; do not query current availability here.
|
|
1250
|
+
const display = candidate;
|
|
1251
|
+
const availability = {
|
|
1252
|
+
...candidate,
|
|
1253
|
+
status: display.status || 'available',
|
|
1254
|
+
maxPartySize: display.maxPartySize ?? params.partySize,
|
|
1255
|
+
reasonCodes: display.reasonCodes || [],
|
|
1256
|
+
requirementGroups: display.requirementGroups || []
|
|
1257
|
+
};
|
|
1258
|
+
return {
|
|
1259
|
+
ok: conflicts.length === 0,
|
|
1260
|
+
status: availability.status,
|
|
1261
|
+
assignments,
|
|
1262
|
+
conflicts,
|
|
1263
|
+
availability
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1220
1266
|
class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
1221
1267
|
defaultName = 'unifiedBookingSales';
|
|
1222
1268
|
defaultVersion = '1.0.0';
|
|
@@ -1254,6 +1300,26 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1254
1300
|
allergyItemRuleConfigs = [];
|
|
1255
1301
|
allergyItemRuleConfigsPromise = null;
|
|
1256
1302
|
async initialize(core, options = {}) {
|
|
1303
|
+
const startedAt = Date.now();
|
|
1304
|
+
const initializationGeneration = this.runtimeInitializationGeneration + 1;
|
|
1305
|
+
try {
|
|
1306
|
+
const initialized = await this.initializeUnifiedSalesRuntime(core, options);
|
|
1307
|
+
if (initialized && !this.runtimeOpenDataDestroyed && initializationGeneration === this.runtimeInitializationGeneration) {
|
|
1308
|
+
this.writeSolutionLog('info', 'initialize success', {
|
|
1309
|
+
action: 'initialize',
|
|
1310
|
+
durationMs: Date.now() - startedAt
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
} catch (error) {
|
|
1314
|
+
if (!this.runtimeOpenDataDestroyed && initializationGeneration === this.runtimeInitializationGeneration) {
|
|
1315
|
+
this.logSolutionFailure('initialize', error, {
|
|
1316
|
+
durationMs: Date.now() - startedAt
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
throw error;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
async initializeUnifiedSalesRuntime(core, options) {
|
|
1257
1323
|
const initializationGeneration = ++this.runtimeInitializationGeneration;
|
|
1258
1324
|
this.resetRuntimeOpenData();
|
|
1259
1325
|
this.runtimeOpenDataDestroyed = false;
|
|
@@ -1269,12 +1335,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1269
1335
|
await initialization;
|
|
1270
1336
|
if (this.runtimeOpenDataDestroyed || initializationGeneration !== this.runtimeInitializationGeneration) {
|
|
1271
1337
|
// A destroyed/reinitialized instance must not publish a ready snapshot.
|
|
1272
|
-
return;
|
|
1338
|
+
return false;
|
|
1273
1339
|
}
|
|
1274
1340
|
if (core !== this.core || openDataModule !== this.store.openData || scope !== this.getRuntimeOpenDataScope()) {
|
|
1275
1341
|
throw new Error('Store settings changed. Please try again.');
|
|
1276
1342
|
}
|
|
1277
1343
|
this.captureAvailabilityScheduleCatalog();
|
|
1344
|
+
return !this.runtimeOpenDataDestroyed && initializationGeneration === this.runtimeInitializationGeneration;
|
|
1278
1345
|
}
|
|
1279
1346
|
getSubmitOrderSalesChannel() {
|
|
1280
1347
|
const channel = String(this.otherParams?.channel ?? '').trim();
|
|
@@ -1340,9 +1407,20 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1340
1407
|
businessCode: String(otherParams.businessCode ?? otherParams.business_code ?? ''),
|
|
1341
1408
|
channel: String(otherParams.channel ?? ''),
|
|
1342
1409
|
platform: String(otherParams.platform ?? ''),
|
|
1343
|
-
businessTimezone: String(otherParams.businessTimezone ?? '')
|
|
1410
|
+
businessTimezone: String(otherParams.businessTimezone ?? ''),
|
|
1411
|
+
...(this.isVenueKioskPlatform(otherParams) ? {
|
|
1412
|
+
venueBookingMode: otherParams.venueBookingMode
|
|
1413
|
+
} : {})
|
|
1344
1414
|
};
|
|
1345
1415
|
}
|
|
1416
|
+
|
|
1417
|
+
/** Kiosk keeps its device/channel semantics; only explicit Venue templates opt in. */
|
|
1418
|
+
isVenueKioskPlatform(otherParams = this.otherParams || {}) {
|
|
1419
|
+
return (0, _platform.normalizeRuntimePlatform)(otherParams.platform) === 'kiosk' && (otherParams.venueBookingMode === 'tickets' || otherParams.venueBookingMode === 'party');
|
|
1420
|
+
}
|
|
1421
|
+
supportsVenueSelectionSnapshot() {
|
|
1422
|
+
return (0, _platform.isCustomerUserPlatform)(this.otherParams?.platform) || this.isVenueKioskPlatform();
|
|
1423
|
+
}
|
|
1346
1424
|
normalizeAvailabilityIdList(values) {
|
|
1347
1425
|
if (!Array.isArray(values) || values.length === 0) return undefined;
|
|
1348
1426
|
const uniqueMap = new Map();
|
|
@@ -1403,6 +1481,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1403
1481
|
const currentTarget = businessCode && channel ? `${businessCode}+${channel}` : null;
|
|
1404
1482
|
let openData = (!currentTarget || this.openDataTarget === currentTarget) && (this.runtimeOpenDataScope === null || this.runtimeOpenDataScope === this.getRuntimeOpenDataScope()) ? this.otherParams?.openData : null;
|
|
1405
1483
|
if (!openData && this.store.openData) {
|
|
1484
|
+
const logContext = this.getSolutionLogContext();
|
|
1406
1485
|
try {
|
|
1407
1486
|
openData = await this.getOpenData();
|
|
1408
1487
|
} catch (error) {
|
|
@@ -1413,7 +1492,9 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1413
1492
|
cause: error instanceof Error ? error.message : String(error)
|
|
1414
1493
|
});
|
|
1415
1494
|
}
|
|
1416
|
-
|
|
1495
|
+
this.logSolutionFailure('resolveAvailabilityTimeSlice', error, {
|
|
1496
|
+
fallback: 'default'
|
|
1497
|
+
}, logContext, 'warning');
|
|
1417
1498
|
}
|
|
1418
1499
|
}
|
|
1419
1500
|
const operatingScheduleIds = this.normalizeAvailabilityIdList(Array.isArray(openData?.['availability.operating_hours']) ? openData?.['availability.operating_hours'] : undefined) || [];
|
|
@@ -1485,7 +1566,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1485
1566
|
if (explicitlySetsOpenData) {
|
|
1486
1567
|
this.openDataTarget = this.otherParams?.openData && nextScope.businessCode && nextScope.channel ? `${nextScope.businessCode}+${nextScope.channel}` : null;
|
|
1487
1568
|
}
|
|
1488
|
-
const shouldResetAvailabilityState = previousScope.cacheId !== nextScope.cacheId || previousScope.businessCode !== nextScope.businessCode || previousScope.channel !== nextScope.channel || previousScope.platform !== nextScope.platform || previousScope.businessTimezone !== nextScope.businessTimezone;
|
|
1569
|
+
const shouldResetAvailabilityState = previousScope.cacheId !== nextScope.cacheId || previousScope.businessCode !== nextScope.businessCode || previousScope.channel !== nextScope.channel || previousScope.platform !== nextScope.platform || previousScope.businessTimezone !== nextScope.businessTimezone || previousScope.venueBookingMode !== nextScope.venueBookingMode;
|
|
1489
1570
|
if (shouldResetAvailabilityState) {
|
|
1490
1571
|
await this.resetAvailabilityProjectionState('set_other_params_reset');
|
|
1491
1572
|
}
|
|
@@ -1557,7 +1638,83 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1557
1638
|
contextId: context.contextId
|
|
1558
1639
|
};
|
|
1559
1640
|
}
|
|
1641
|
+
getSolutionLogContext() {
|
|
1642
|
+
const context = {};
|
|
1643
|
+
try {
|
|
1644
|
+
Object.assign(context, {
|
|
1645
|
+
solutionName: this.name,
|
|
1646
|
+
moduleName: this.defaultName,
|
|
1647
|
+
module: 'unifiedBookingSales',
|
|
1648
|
+
cacheId: this.cacheId,
|
|
1649
|
+
businessCode: this.otherParams?.businessCode ?? this.otherParams?.business_code,
|
|
1650
|
+
platform: this.otherParams?.platform,
|
|
1651
|
+
channel: this.otherParams?.channel
|
|
1652
|
+
});
|
|
1653
|
+
try {
|
|
1654
|
+
const order = this.getTempOrder();
|
|
1655
|
+
Object.assign(context, {
|
|
1656
|
+
orderId: order?.order_id,
|
|
1657
|
+
externalSaleNumber: order?.external_sale_number,
|
|
1658
|
+
shopOrderNumber: order?.shop_order_number
|
|
1659
|
+
});
|
|
1660
|
+
} catch {/* A partially initialized order must not hide the failure log. */}
|
|
1661
|
+
try {
|
|
1662
|
+
const order = this.store.order;
|
|
1663
|
+
context.orderSessionId = order?.getOrderSessionId?.() ?? null;
|
|
1664
|
+
} catch {/* Session context is optional during initialization and teardown. */}
|
|
1665
|
+
} catch {/* Basic context remains useful even when some runtime fields cannot be read. */}
|
|
1666
|
+
return context;
|
|
1667
|
+
}
|
|
1668
|
+
writeSolutionLog(type, title, metadata = {}, context = this.getSolutionLogContext()) {
|
|
1669
|
+
try {
|
|
1670
|
+
(0, _hostLogger.writeHostLog)(this.core, {
|
|
1671
|
+
type,
|
|
1672
|
+
title: `[UnifiedBookingSales] ${title}`,
|
|
1673
|
+
metadata: {
|
|
1674
|
+
...context,
|
|
1675
|
+
...metadata
|
|
1676
|
+
}
|
|
1677
|
+
});
|
|
1678
|
+
} catch {
|
|
1679
|
+
// Reading diagnostic context must not change the sales result.
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
logSolutionFailure(method, error, metadata = {}, context, type) {
|
|
1683
|
+
try {
|
|
1684
|
+
const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : undefined;
|
|
1685
|
+
const isBusinessFailure = error instanceof _ResourcePlanner.AvailabilityError && code !== 'OPERATING_HOURS_RESOLVE_FAILED' && code !== 'SELF_EXCLUSION_RESOLVE_FAILED';
|
|
1686
|
+
this.writeSolutionLog(type ?? (code === 'AVAILABILITY_COMMIT_IN_PROGRESS' ? 'debug' : isBusinessFailure || code === 'REQUIRED_PRODUCT_MISSING' ? 'warning' : 'error'), `${method} failed`, {
|
|
1687
|
+
...metadata,
|
|
1688
|
+
action: method,
|
|
1689
|
+
errorCode: code,
|
|
1690
|
+
errorMessage: (error instanceof Error ? error.message : String(error)).slice(0, 500)
|
|
1691
|
+
}, context);
|
|
1692
|
+
} catch {
|
|
1693
|
+
// Error serialization is observational only.
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1560
1696
|
async emitAvailabilityDiagnostic(payload) {
|
|
1697
|
+
try {
|
|
1698
|
+
const projection = payload.projection;
|
|
1699
|
+
this.writeSolutionLog(payload.action === 'prepare' || payload.action === 'refresh' ? 'info' : 'debug', `availability ${payload.action}`, {
|
|
1700
|
+
action: payload.action,
|
|
1701
|
+
reason: payload.reason,
|
|
1702
|
+
contextId: payload.contextId,
|
|
1703
|
+
contextVersion: payload.contextVersion,
|
|
1704
|
+
snapshotId: payload.snapshotId,
|
|
1705
|
+
orderRevision: payload.orderRevision,
|
|
1706
|
+
previousOrderRevision: payload.previousOrderRevision,
|
|
1707
|
+
registrySize: this.availabilityContextRegistry.size,
|
|
1708
|
+
projectionPoolSize: this.availabilityProjectionPool.size,
|
|
1709
|
+
...(projection ? {
|
|
1710
|
+
productCount: projection.products.length,
|
|
1711
|
+
resourceCount: projection.resources.length,
|
|
1712
|
+
occupancyCount: projection.resourceOccupancies.length
|
|
1713
|
+
} : {})
|
|
1714
|
+
});
|
|
1715
|
+
} catch {
|
|
1716
|
+
// Diagnostic summaries must not change the existing effects event.
|
|
1717
|
+
}
|
|
1561
1718
|
await this.core?.effects?.emit?.(`${this.name}:${_types.UnifiedBookingSalesHooks.onAvailabilityProjectionDiagnostic}`, {
|
|
1562
1719
|
...payload,
|
|
1563
1720
|
registrySize: this.availabilityContextRegistry.size,
|
|
@@ -1725,6 +1882,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1725
1882
|
});
|
|
1726
1883
|
}
|
|
1727
1884
|
const tempOrder = await super.addNewOrder();
|
|
1885
|
+
const logContext = this.getSolutionLogContext();
|
|
1728
1886
|
if (sessionRecord) {
|
|
1729
1887
|
this.store.order?.persistTempOrder();
|
|
1730
1888
|
}
|
|
@@ -1735,13 +1893,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1735
1893
|
await this.refreshLegacySessionCustomerDiscounts(tempOrder);
|
|
1736
1894
|
}
|
|
1737
1895
|
} catch (error) {
|
|
1738
|
-
|
|
1896
|
+
this.logSolutionFailure('syncAuthenticatedOrderCustomer', error, {}, logContext, 'warning');
|
|
1739
1897
|
}
|
|
1740
1898
|
} else if (sessionRecord) {
|
|
1741
1899
|
try {
|
|
1742
1900
|
await this.refreshLegacySessionCustomerDiscounts(tempOrder);
|
|
1743
1901
|
} catch (error) {
|
|
1744
|
-
|
|
1902
|
+
this.logSolutionFailure('refreshLegacySessionCustomerDiscounts', error, {}, logContext, 'warning');
|
|
1745
1903
|
}
|
|
1746
1904
|
}
|
|
1747
1905
|
return this.store.order?.getTempOrder() || tempOrder;
|
|
@@ -1833,10 +1991,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
1833
1991
|
this.otherParams.openData = injectedOpenData;
|
|
1834
1992
|
this.openDataTarget = `${businessCode}+${this.getSubmitOrderSalesChannel()}`;
|
|
1835
1993
|
}
|
|
1994
|
+
const logContext = this.getSolutionLogContext();
|
|
1836
1995
|
try {
|
|
1837
1996
|
await this.loadOpenDataConfig();
|
|
1838
1997
|
} catch (error) {
|
|
1839
|
-
|
|
1998
|
+
this.logSolutionFailure('prepareInvoiceTemplateAtSolutionReady', error, {
|
|
1999
|
+
fallback: 'default'
|
|
2000
|
+
}, logContext, 'warning');
|
|
1840
2001
|
}
|
|
1841
2002
|
}
|
|
1842
2003
|
async loadOpenDataConfig() {
|
|
@@ -2053,6 +2214,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2053
2214
|
}
|
|
2054
2215
|
async fetchAllergyItemRuleConfigs(strategyModelIds) {
|
|
2055
2216
|
if (!strategyModelIds.length) return [];
|
|
2217
|
+
const logContext = this.getSolutionLogContext();
|
|
2056
2218
|
try {
|
|
2057
2219
|
const response = await this.request.get('/promotion', {
|
|
2058
2220
|
skip: 1,
|
|
@@ -2066,9 +2228,9 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2066
2228
|
const list = response.data.list;
|
|
2067
2229
|
return normalizeItemRuleStrategyConfigs(list.map(item => item?.metadata));
|
|
2068
2230
|
} catch (error) {
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2231
|
+
this.logSolutionFailure('fetchAllergyItemRuleConfigs', error, {
|
|
2232
|
+
strategyModelIds
|
|
2233
|
+
}, logContext);
|
|
2072
2234
|
throw error;
|
|
2073
2235
|
}
|
|
2074
2236
|
}
|
|
@@ -2354,7 +2516,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2354
2516
|
|
|
2355
2517
|
/** One complete raw product query per explicitly configured pool for this page lifetime. */
|
|
2356
2518
|
createVenueCatalogSession(params) {
|
|
2357
|
-
if (!
|
|
2519
|
+
if (!this.supportsVenueSelectionSnapshot()) {
|
|
2358
2520
|
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_PLATFORM_UNSUPPORTED', 'Venue catalog sessions require a customer platform.');
|
|
2359
2521
|
}
|
|
2360
2522
|
const ids = params.menu_list_ids;
|
|
@@ -2366,6 +2528,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2366
2528
|
const generation = this.runtimeInitializationGeneration;
|
|
2367
2529
|
const core = this.core;
|
|
2368
2530
|
const request = this.request;
|
|
2531
|
+
const venueKioskMode = this.isVenueKioskPlatform() ? this.otherParams.venueBookingMode : undefined;
|
|
2369
2532
|
const entry = {
|
|
2370
2533
|
scope,
|
|
2371
2534
|
generation,
|
|
@@ -2386,7 +2549,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2386
2549
|
if (!this.venueCatalogSessions.has(entry)) {
|
|
2387
2550
|
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_DISPOSED', 'The venue catalog session is closed.');
|
|
2388
2551
|
}
|
|
2389
|
-
if (this.runtimeOpenDataDestroyed || this.core !== core || this.request !== request || generation !== this.runtimeInitializationGeneration || scope !== this.getRuntimeOpenDataScope()) {
|
|
2552
|
+
if (this.runtimeOpenDataDestroyed || this.core !== core || this.request !== request || generation !== this.runtimeInitializationGeneration || scope !== this.getRuntimeOpenDataScope() || !this.supportsVenueSelectionSnapshot() || venueKioskMode !== (this.isVenueKioskPlatform() ? this.otherParams.venueBookingMode : undefined)) {
|
|
2390
2553
|
throw (0, _venueCatalogSession.venueCatalogError)('VENUE_CATALOG_STALE', 'The venue store context changed. Reopen the booking page.');
|
|
2391
2554
|
}
|
|
2392
2555
|
};
|
|
@@ -2423,7 +2586,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2423
2586
|
const queryPayload = {
|
|
2424
2587
|
schedule_date: datetime.slice(0, 10),
|
|
2425
2588
|
schedule_datetime: datetime,
|
|
2426
|
-
customer_id: input.customer_id ?? this.getTempOrder()?.customer_id ?? user?.get?.()?.id,
|
|
2589
|
+
customer_id: input.customer_id ?? this.getTempOrder()?.customer_id ?? (this.isVenueKioskPlatform() ? undefined : user?.get?.()?.id),
|
|
2427
2590
|
strategy_context: {
|
|
2428
2591
|
...this.getPriceQueryStrategyContext(),
|
|
2429
2592
|
...(input.strategy_context || {})
|
|
@@ -3402,12 +3565,18 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
3402
3565
|
const cachedRawResources = this.availabilityRemoteOccupancyCache.read(cacheParams);
|
|
3403
3566
|
if (cachedRawResources) {
|
|
3404
3567
|
if (params.useCacheOnHit) {
|
|
3568
|
+
const logContext = this.getSolutionLogContext();
|
|
3405
3569
|
void this.refreshAvailabilityRemoteResourceQuery({
|
|
3406
3570
|
timezone: params.timezone,
|
|
3407
3571
|
dateRange: params.dateRange,
|
|
3408
3572
|
resourceIds: normalizedResourceIds
|
|
3409
3573
|
}).catch(error => {
|
|
3410
|
-
|
|
3574
|
+
this.logSolutionFailure('refreshAvailabilityRemoteResources', error, {
|
|
3575
|
+
resourceCount: normalizedResourceIds.length,
|
|
3576
|
+
dateRange: {
|
|
3577
|
+
...params.dateRange
|
|
3578
|
+
}
|
|
3579
|
+
}, logContext, 'warning');
|
|
3411
3580
|
});
|
|
3412
3581
|
}
|
|
3413
3582
|
return cachedRawResources;
|
|
@@ -3933,6 +4102,18 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
3933
4102
|
}
|
|
3934
4103
|
}
|
|
3935
4104
|
}
|
|
4105
|
+
|
|
4106
|
+
/** Read an existing customer selection without refreshing its clock or occupancy snapshot. */
|
|
4107
|
+
getCustomerSelectionProjection(contextId) {
|
|
4108
|
+
const context = this.getAvailabilityContextEntry(contextId);
|
|
4109
|
+
const projectionEntry = this.getActiveAvailabilityProjectionEntry(context);
|
|
4110
|
+
if (!projectionEntry) throw this.createAvailabilityFacadeError('AVAILABILITY_CONTEXT_NOT_FOUND', '所选商品上下文已关闭,请重新打开商品');
|
|
4111
|
+
return {
|
|
4112
|
+
context,
|
|
4113
|
+
projectionEntry,
|
|
4114
|
+
refreshed: false
|
|
4115
|
+
};
|
|
4116
|
+
}
|
|
3936
4117
|
async ensureAvailabilityContextProjection(contextId, reason) {
|
|
3937
4118
|
let retries = 0;
|
|
3938
4119
|
while (retries < 3) {
|
|
@@ -4014,6 +4195,18 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4014
4195
|
|
|
4015
4196
|
/** IO boundary: loads catalog, schedules, resources, occupancies, and registers one context. */
|
|
4016
4197
|
async prepareAvailabilityProjection(params) {
|
|
4198
|
+
const logContext = this.getSolutionLogContext();
|
|
4199
|
+
try {
|
|
4200
|
+
return await this.prepareAvailabilityContext(params);
|
|
4201
|
+
} catch (error) {
|
|
4202
|
+
this.logSolutionFailure('prepareAvailabilityProjection', error, {
|
|
4203
|
+
productCount: params?.productIds?.length,
|
|
4204
|
+
resourceCount: params?.resourceIds?.length
|
|
4205
|
+
}, logContext);
|
|
4206
|
+
throw error;
|
|
4207
|
+
}
|
|
4208
|
+
}
|
|
4209
|
+
async prepareAvailabilityContext(params) {
|
|
4017
4210
|
this.assertAvailabilityPrepareParams(params);
|
|
4018
4211
|
const paramsWithDefaults = await this.resolveAvailabilityPrepareDefaults(params);
|
|
4019
4212
|
const {
|
|
@@ -4082,15 +4275,19 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4082
4275
|
|
|
4083
4276
|
/** Thin facade: auto-refresh on cart drift, then delegate to the pure projection query. */
|
|
4084
4277
|
async queryBookingAvailability(contextId, request) {
|
|
4278
|
+
const customerSelectionSnapshot = request.target === 'resource' && request.customerSelectionSnapshot === true && this.supportsVenueSelectionSnapshot();
|
|
4085
4279
|
const {
|
|
4086
4280
|
context,
|
|
4087
4281
|
projectionEntry,
|
|
4088
4282
|
refreshed
|
|
4089
|
-
} = await this.ensureAvailabilityContextProjection(contextId, 'query_booking_availability');
|
|
4283
|
+
} = customerSelectionSnapshot ? this.getCustomerSelectionProjection(contextId) : await this.ensureAvailabilityContextProjection(contextId, 'query_booking_availability');
|
|
4090
4284
|
this.assertContextualQueryFreshness(context, request);
|
|
4091
4285
|
const strictAvailability = context.prepareParams.strictAvailability === true;
|
|
4092
4286
|
const isPosAvailabilityRequest = String(this.otherParams?.platform ?? '').trim().toLowerCase() === 'pos';
|
|
4093
4287
|
const result = (0, _ResourcePlanner.queryAvailabilityProjection)(projectionEntry.projection, request, {
|
|
4288
|
+
...(customerSelectionSnapshot ? {
|
|
4289
|
+
evaluatedAt: projectionEntry.projection.meta.now
|
|
4290
|
+
} : {}),
|
|
4094
4291
|
useExactDurationCandidateMinute: isPosAvailabilityRequest && !strictAvailability,
|
|
4095
4292
|
allowExcludedScheduleDateOverride: isPosAvailabilityRequest && !strictAvailability
|
|
4096
4293
|
});
|
|
@@ -4185,8 +4382,20 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4185
4382
|
return (this.getTempOrder()?.bookings || []).find(booking => bookingUid && getBookingUid(booking) === bookingUid || productUid && String(booking.product_uid ?? '') === productUid);
|
|
4186
4383
|
}
|
|
4187
4384
|
|
|
4188
|
-
/**
|
|
4385
|
+
/** Customer snapshot writes defer availability to checkout; other callers retain cache revalidation. */
|
|
4189
4386
|
async commitAvailabilitySelection(contextId, params) {
|
|
4387
|
+
const logContext = this.getSolutionLogContext();
|
|
4388
|
+
try {
|
|
4389
|
+
return await this.commitAvailabilitySelectionWithLock(contextId, params);
|
|
4390
|
+
} catch (error) {
|
|
4391
|
+
this.logSolutionFailure('commitAvailabilitySelection', error, {
|
|
4392
|
+
contextId,
|
|
4393
|
+
mode: params?.mode
|
|
4394
|
+
}, logContext);
|
|
4395
|
+
throw error;
|
|
4396
|
+
}
|
|
4397
|
+
}
|
|
4398
|
+
async commitAvailabilitySelectionWithLock(contextId, params) {
|
|
4190
4399
|
const normalizedContextId = String(contextId || '').trim();
|
|
4191
4400
|
if (!normalizedContextId) {
|
|
4192
4401
|
throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', 'commitAvailabilitySelection 缺少 contextId', {
|
|
@@ -4198,8 +4407,9 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4198
4407
|
if (isPartyReplacement && (!isEditingSelection || !Array.isArray(params.relatedRetailProducts))) {
|
|
4199
4408
|
throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', 'Party replacement requires edit/replace mode and the confirmed complete extras array');
|
|
4200
4409
|
}
|
|
4410
|
+
const customerSelectionSnapshot = params.customerSelectionSnapshot === true && this.supportsVenueSelectionSnapshot();
|
|
4201
4411
|
const strictAvailability = this.availabilityContextRegistry.get(normalizedContextId)?.prepareParams.strictAvailability === true;
|
|
4202
|
-
const hasCommitGuard = strictAvailability || isPartyReplacement || Boolean(params.availabilityCommitGuard);
|
|
4412
|
+
const hasCommitGuard = customerSelectionSnapshot || strictAvailability || isPartyReplacement || Boolean(params.availabilityCommitGuard);
|
|
4203
4413
|
params.availabilityCommitGuard?.();
|
|
4204
4414
|
// Stabilize the locally generated sale identity before taking the guard snapshot.
|
|
4205
4415
|
if (hasCommitGuard) this.store.order?.ensureTempOrder?.();
|
|
@@ -4244,7 +4454,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4244
4454
|
context,
|
|
4245
4455
|
projectionEntry,
|
|
4246
4456
|
refreshed
|
|
4247
|
-
} = await this.ensureAvailabilityContextProjection(normalizedContextId, 'commit_precheck');
|
|
4457
|
+
} = customerSelectionSnapshot ? this.getCustomerSelectionProjection(normalizedContextId) : await this.ensureAvailabilityContextProjection(normalizedContextId, 'commit_precheck');
|
|
4248
4458
|
if (refreshed) {
|
|
4249
4459
|
throw this.createAvailabilityFacadeError('AVAILABILITY_SELECTION_STALE', 'availability context 已刷新,请重新获取候选', {
|
|
4250
4460
|
contextId: normalizedContextId,
|
|
@@ -4274,7 +4484,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4274
4484
|
projectionContextVersion: projectionEntry.contextVersion
|
|
4275
4485
|
});
|
|
4276
4486
|
}
|
|
4277
|
-
if (projectionEntry.orderRevision !== this.getCurrentOrderRevision()) {
|
|
4487
|
+
if (!customerSelectionSnapshot && projectionEntry.orderRevision !== this.getCurrentOrderRevision()) {
|
|
4278
4488
|
throw this.createAvailabilityFacadeError('AVAILABILITY_SELECTION_STALE', '购物车已变化,请重新获取候选', {
|
|
4279
4489
|
contextId: normalizedContextId,
|
|
4280
4490
|
currentContextVersion: context.activeVersion,
|
|
@@ -4324,18 +4534,22 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4324
4534
|
expectedVersion: context.activeVersion,
|
|
4325
4535
|
expectedRefreshNonce: context.refreshNonce,
|
|
4326
4536
|
expectedLifecycleGeneration: this.availabilityLifecycleGeneration,
|
|
4327
|
-
expectedOrderRevision: String(baseProjection.meta.orderRevision ?? '')
|
|
4537
|
+
expectedOrderRevision: customerSelectionSnapshot ? this.getCurrentOrderRevision() : String(baseProjection.meta.orderRevision ?? '')
|
|
4328
4538
|
};
|
|
4329
4539
|
const prepareParams = baseProjection.meta.prepareParams;
|
|
4330
4540
|
if (!prepareParams) {
|
|
4331
4541
|
throw new _ResourcePlanner.AvailabilityError('REVALIDATION_FAILED', 'projection 缺少 prepareParams,无法执行缓存重校验');
|
|
4332
4542
|
}
|
|
4333
|
-
const fallbackResources = {
|
|
4543
|
+
const fallbackResources = customerSelectionSnapshot ? undefined : {
|
|
4334
4544
|
resources: (0, _lodashEs.cloneDeep)([...(baseProjection.resources || [])]),
|
|
4335
4545
|
resourceOccupancies: (0, _lodashEs.cloneDeep)([...(baseProjection.resourceOccupancies || [])].filter(occupancy => occupancy.source !== 'cart')),
|
|
4336
4546
|
includesInjectedRawOccupancies: true
|
|
4337
4547
|
};
|
|
4338
|
-
const commitSnapshot =
|
|
4548
|
+
const commitSnapshot = customerSelectionSnapshot ? {
|
|
4549
|
+
projection: baseProjection,
|
|
4550
|
+
prepareParams,
|
|
4551
|
+
orderRevision: commitWriteGuard.expectedOrderRevision
|
|
4552
|
+
} : await this.buildAvailabilityProjectionSnapshot({
|
|
4339
4553
|
...this.cloneAvailabilityPrepareParams(prepareParams),
|
|
4340
4554
|
editingProductLineUids: isEditingSelection && params.productLineUid ? [params.productLineUid] : []
|
|
4341
4555
|
}, {
|
|
@@ -4344,7 +4558,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4344
4558
|
durationCandidateAnchorAt: this.getAvailabilityDurationCandidateAnchorAt(baseProjection) || context.durationCandidateAnchorAt
|
|
4345
4559
|
});
|
|
4346
4560
|
const refreshedProjection = commitSnapshot.projection;
|
|
4347
|
-
if (String(refreshedProjection.meta.orderRevision ?? '') !== String(baseProjection.meta.orderRevision ?? '')) {
|
|
4561
|
+
if (!customerSelectionSnapshot && String(refreshedProjection.meta.orderRevision ?? '') !== String(baseProjection.meta.orderRevision ?? '')) {
|
|
4348
4562
|
await this.refreshAvailabilityContextProjection({
|
|
4349
4563
|
contextId: normalizedContextId,
|
|
4350
4564
|
reason: 'commit_order_revision_changed',
|
|
@@ -4365,7 +4579,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4365
4579
|
const candidateDurationMinutes = getCandidateDurationMinutes(params.candidate);
|
|
4366
4580
|
const candidateStartTime = getCandidateStartTime(params.candidate);
|
|
4367
4581
|
const allowPosAvailabilityOverride = String(this.otherParams?.platform ?? '').trim().toLowerCase() === 'pos' && !strictAvailability;
|
|
4368
|
-
const refreshedRanges = (0, _ResourcePlanner.getProductTimeRanges)(refreshedProjection, {
|
|
4582
|
+
const refreshedRanges = customerSelectionSnapshot ? [params.candidate] : (0, _ResourcePlanner.getProductTimeRanges)(refreshedProjection, {
|
|
4369
4583
|
productIds: [params.candidate.productId],
|
|
4370
4584
|
dateRange: {
|
|
4371
4585
|
startDate: params.candidate.startAt.slice(0, 10),
|
|
@@ -4406,7 +4620,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4406
4620
|
productId: refreshedCandidateBase.productId
|
|
4407
4621
|
});
|
|
4408
4622
|
}
|
|
4409
|
-
let validation =
|
|
4623
|
+
let validation = customerSelectionSnapshot ? acceptCustomerSelectionSnapshot({
|
|
4624
|
+
candidate: params.candidate,
|
|
4625
|
+
product,
|
|
4626
|
+
resources: baseProjection.resources,
|
|
4627
|
+
requirementSelections: params.requirementSelections,
|
|
4628
|
+
partySize
|
|
4629
|
+
}) : (0, _ResourcePlanner.validateAvailabilitySelection)(refreshedProjection, {
|
|
4410
4630
|
candidate: refreshedCandidateBase,
|
|
4411
4631
|
requirementSelections: params.requirementSelections,
|
|
4412
4632
|
partySize,
|
|
@@ -4445,7 +4665,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4445
4665
|
// Revalidation failure must leave the caller's candidate reusable. Only publish the
|
|
4446
4666
|
// refreshed projection/version after candidate and resource validation has passed;
|
|
4447
4667
|
// otherwise a second Confirm from the still-open modal would incorrectly become stale.
|
|
4448
|
-
const revalidationEntry = this.storeAvailabilityProjectionEntry({
|
|
4668
|
+
const revalidationEntry = customerSelectionSnapshot ? projectionEntry : this.storeAvailabilityProjectionEntry({
|
|
4449
4669
|
contextId: normalizedContextId,
|
|
4450
4670
|
prepareParams: commitSnapshot.prepareParams,
|
|
4451
4671
|
prepareKey: context.prepareKey,
|
|
@@ -4454,7 +4674,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4454
4674
|
incrementVersion: true
|
|
4455
4675
|
});
|
|
4456
4676
|
const revalidatedContext = this.getAvailabilityContextEntry(normalizedContextId);
|
|
4457
|
-
await this.emitAvailabilityDiagnostic({
|
|
4677
|
+
if (!customerSelectionSnapshot) await this.emitAvailabilityDiagnostic({
|
|
4458
4678
|
action: 'refresh',
|
|
4459
4679
|
contextId: normalizedContextId,
|
|
4460
4680
|
contextVersion: revalidatedContext.activeVersion,
|
|
@@ -4469,7 +4689,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4469
4689
|
expectedVersion: revalidatedContext.activeVersion,
|
|
4470
4690
|
expectedRefreshNonce: revalidatedContext.refreshNonce,
|
|
4471
4691
|
expectedLifecycleGeneration: this.availabilityLifecycleGeneration,
|
|
4472
|
-
expectedOrderRevision: revalidationEntry.orderRevision
|
|
4692
|
+
expectedOrderRevision: customerSelectionSnapshot ? commitWriteGuard.expectedOrderRevision : revalidationEntry.orderRevision
|
|
4473
4693
|
};
|
|
4474
4694
|
const refreshedCandidate = this.decorateAvailabilityCandidate(normalizedContextId, revalidatedContext.activeVersion, refreshedCandidateBase);
|
|
4475
4695
|
// Order may await line/runtime setup. Its guarded transaction invokes this
|
|
@@ -4480,7 +4700,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
4480
4700
|
if (!availabilityCommitTargetGuard()) {
|
|
4481
4701
|
throw this.createAvailabilityFacadeError('AVAILABILITY_SELECTION_STALE', '预约加购期间订单或业务已变化');
|
|
4482
4702
|
}
|
|
4483
|
-
if (!strictAvailability) return;
|
|
4703
|
+
if (customerSelectionSnapshot || !strictAvailability) return;
|
|
4484
4704
|
const currentValidation = (0, _ResourcePlanner.validateAvailabilitySelection)(refreshedProjection, {
|
|
4485
4705
|
candidate: refreshedCandidateBase,
|
|
4486
4706
|
requirementSelections: params.requirementSelections,
|
|
@@ -59,6 +59,8 @@ export declare enum UnifiedBookingSalesHooks {
|
|
|
59
59
|
}
|
|
60
60
|
export interface UnifiedBookingSalesOtherParams extends Record<string, any> {
|
|
61
61
|
enableSessionStoragePersist?: boolean;
|
|
62
|
+
/** Explicitly opts the real Kiosk host into the Tickets/Party self-service contracts. */
|
|
63
|
+
venueBookingMode?: 'tickets' | 'party';
|
|
62
64
|
}
|
|
63
65
|
export type UnifiedBookingSalesAllergyRequirement = AllergyRequirement;
|
|
64
66
|
export interface UnifiedBookingSalesResolveProductAllergyRequirementParams {
|
|
@@ -145,6 +147,8 @@ export type ContextualAvailabilityQuery = Omit<Extract<AvailabilityQuery, {
|
|
|
145
147
|
target: 'resource';
|
|
146
148
|
}>, 'selectedRanges'> & {
|
|
147
149
|
selectedRanges: ContextualProductTimeRange[];
|
|
150
|
+
/** PC/H5 and explicitly enabled Venue Kiosk templates retain the already-selected time. */
|
|
151
|
+
customerSelectionSnapshot?: boolean;
|
|
148
152
|
});
|
|
149
153
|
export type ContextualTimeAvailabilityItem = Omit<TimeAvailabilityItem, keyof ProductTimeRange> & ContextualProductTimeRange;
|
|
150
154
|
export interface ContextualTimeAvailabilityGroup extends Omit<TimeAvailabilityGroup, 'times'> {
|
|
@@ -210,6 +214,8 @@ export interface UnifiedBookingSalesAddRetailProductParams {
|
|
|
210
214
|
}
|
|
211
215
|
export interface ContextualCommitAvailabilitySelectionParams {
|
|
212
216
|
mode: 'add' | 'edit' | 'replace';
|
|
217
|
+
/** PC/H5 and enabled Venue Kiosk templates write the selected snapshot; checkout is authoritative. */
|
|
218
|
+
customerSelectionSnapshot?: boolean;
|
|
213
219
|
/** Local UI intent guard, checked again immediately before the Order mutation. */
|
|
214
220
|
availabilityCommitGuard?: () => void;
|
|
215
221
|
productLineUid?: string;
|