@pisell/pisellos 0.10.81 → 0.10.82

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.
Files changed (42) hide show
  1. package/dist/modules/Product/index.d.ts +1 -1
  2. package/dist/modules/ProductList/index.js +5 -0
  3. package/dist/modules/ResourcePlanner/planner.js +2 -1
  4. package/dist/solution/BookingByStep/index.d.ts +1 -1
  5. package/dist/solution/BookingTicket/index.d.ts +1 -1
  6. package/dist/solution/BookingTicket/index.js +36 -31
  7. package/dist/solution/ScanOrder/index.d.ts +0 -1
  8. package/dist/solution/ScanOrder/index.js +62 -59
  9. package/dist/solution/ScanOrder/types.d.ts +2 -0
  10. package/dist/solution/ScanOrder/types.js +2 -0
  11. package/dist/solution/UnifiedBookingSales/index.d.ts +9 -1
  12. package/dist/solution/UnifiedBookingSales/index.js +1438 -1125
  13. package/dist/solution/UnifiedBookingSales/types.d.ts +4 -0
  14. package/dist/solution/VenueBooking/index.js +111 -104
  15. package/dist/solution/VenueBooking/types.d.ts +2 -0
  16. package/dist/solution/VenueBooking/types.js +3 -1
  17. package/dist/solution/VenueBooking/utils/smartPricing.d.ts +1 -0
  18. package/dist/solution/VenueBooking/utils/smartPricing.js +6 -1
  19. package/dist/utils/hostLogger.d.ts +10 -0
  20. package/dist/utils/hostLogger.js +20 -0
  21. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  22. package/lib/modules/Product/index.d.ts +1 -1
  23. package/lib/modules/ProductList/index.js +5 -0
  24. package/lib/modules/ResourcePlanner/planner.js +2 -1
  25. package/lib/solution/BookingByStep/index.d.ts +1 -1
  26. package/lib/solution/BookingTicket/index.d.ts +1 -1
  27. package/lib/solution/BookingTicket/index.js +5 -4
  28. package/lib/solution/ScanOrder/index.d.ts +0 -1
  29. package/lib/solution/ScanOrder/index.js +47 -41
  30. package/lib/solution/ScanOrder/types.d.ts +2 -0
  31. package/lib/solution/ScanOrder/types.js +1 -0
  32. package/lib/solution/UnifiedBookingSales/index.d.ts +9 -1
  33. package/lib/solution/UnifiedBookingSales/index.js +232 -24
  34. package/lib/solution/UnifiedBookingSales/types.d.ts +4 -0
  35. package/lib/solution/VenueBooking/index.js +38 -47
  36. package/lib/solution/VenueBooking/types.d.ts +2 -0
  37. package/lib/solution/VenueBooking/types.js +3 -1
  38. package/lib/solution/VenueBooking/utils/smartPricing.d.ts +1 -0
  39. package/lib/solution/VenueBooking/utils/smartPricing.js +6 -1
  40. package/lib/utils/hostLogger.d.ts +10 -0
  41. package/lib/utils/hostLogger.js +25 -0
  42. 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();
@@ -1403,6 +1470,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1403
1470
  const currentTarget = businessCode && channel ? `${businessCode}+${channel}` : null;
1404
1471
  let openData = (!currentTarget || this.openDataTarget === currentTarget) && (this.runtimeOpenDataScope === null || this.runtimeOpenDataScope === this.getRuntimeOpenDataScope()) ? this.otherParams?.openData : null;
1405
1472
  if (!openData && this.store.openData) {
1473
+ const logContext = this.getSolutionLogContext();
1406
1474
  try {
1407
1475
  openData = await this.getOpenData();
1408
1476
  } catch (error) {
@@ -1413,7 +1481,9 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1413
1481
  cause: error instanceof Error ? error.message : String(error)
1414
1482
  });
1415
1483
  }
1416
- console.warn('[UnifiedBookingSales] OpenData 时间切片配置加载失败,回退为默认值', error);
1484
+ this.logSolutionFailure('resolveAvailabilityTimeSlice', error, {
1485
+ fallback: 'default'
1486
+ }, logContext, 'warning');
1417
1487
  }
1418
1488
  }
1419
1489
  const operatingScheduleIds = this.normalizeAvailabilityIdList(Array.isArray(openData?.['availability.operating_hours']) ? openData?.['availability.operating_hours'] : undefined) || [];
@@ -1557,7 +1627,83 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1557
1627
  contextId: context.contextId
1558
1628
  };
1559
1629
  }
1630
+ getSolutionLogContext() {
1631
+ const context = {};
1632
+ try {
1633
+ Object.assign(context, {
1634
+ solutionName: this.name,
1635
+ moduleName: this.defaultName,
1636
+ module: 'unifiedBookingSales',
1637
+ cacheId: this.cacheId,
1638
+ businessCode: this.otherParams?.businessCode ?? this.otherParams?.business_code,
1639
+ platform: this.otherParams?.platform,
1640
+ channel: this.otherParams?.channel
1641
+ });
1642
+ try {
1643
+ const order = this.getTempOrder();
1644
+ Object.assign(context, {
1645
+ orderId: order?.order_id,
1646
+ externalSaleNumber: order?.external_sale_number,
1647
+ shopOrderNumber: order?.shop_order_number
1648
+ });
1649
+ } catch {/* A partially initialized order must not hide the failure log. */}
1650
+ try {
1651
+ const order = this.store.order;
1652
+ context.orderSessionId = order?.getOrderSessionId?.() ?? null;
1653
+ } catch {/* Session context is optional during initialization and teardown. */}
1654
+ } catch {/* Basic context remains useful even when some runtime fields cannot be read. */}
1655
+ return context;
1656
+ }
1657
+ writeSolutionLog(type, title, metadata = {}, context = this.getSolutionLogContext()) {
1658
+ try {
1659
+ (0, _hostLogger.writeHostLog)(this.core, {
1660
+ type,
1661
+ title: `[UnifiedBookingSales] ${title}`,
1662
+ metadata: {
1663
+ ...context,
1664
+ ...metadata
1665
+ }
1666
+ });
1667
+ } catch {
1668
+ // Reading diagnostic context must not change the sales result.
1669
+ }
1670
+ }
1671
+ logSolutionFailure(method, error, metadata = {}, context, type) {
1672
+ try {
1673
+ const code = error && typeof error === 'object' && 'code' in error ? String(error.code) : undefined;
1674
+ const isBusinessFailure = error instanceof _ResourcePlanner.AvailabilityError && code !== 'OPERATING_HOURS_RESOLVE_FAILED' && code !== 'SELF_EXCLUSION_RESOLVE_FAILED';
1675
+ this.writeSolutionLog(type ?? (code === 'AVAILABILITY_COMMIT_IN_PROGRESS' ? 'debug' : isBusinessFailure || code === 'REQUIRED_PRODUCT_MISSING' ? 'warning' : 'error'), `${method} failed`, {
1676
+ ...metadata,
1677
+ action: method,
1678
+ errorCode: code,
1679
+ errorMessage: (error instanceof Error ? error.message : String(error)).slice(0, 500)
1680
+ }, context);
1681
+ } catch {
1682
+ // Error serialization is observational only.
1683
+ }
1684
+ }
1560
1685
  async emitAvailabilityDiagnostic(payload) {
1686
+ try {
1687
+ const projection = payload.projection;
1688
+ this.writeSolutionLog(payload.action === 'prepare' || payload.action === 'refresh' ? 'info' : 'debug', `availability ${payload.action}`, {
1689
+ action: payload.action,
1690
+ reason: payload.reason,
1691
+ contextId: payload.contextId,
1692
+ contextVersion: payload.contextVersion,
1693
+ snapshotId: payload.snapshotId,
1694
+ orderRevision: payload.orderRevision,
1695
+ previousOrderRevision: payload.previousOrderRevision,
1696
+ registrySize: this.availabilityContextRegistry.size,
1697
+ projectionPoolSize: this.availabilityProjectionPool.size,
1698
+ ...(projection ? {
1699
+ productCount: projection.products.length,
1700
+ resourceCount: projection.resources.length,
1701
+ occupancyCount: projection.resourceOccupancies.length
1702
+ } : {})
1703
+ });
1704
+ } catch {
1705
+ // Diagnostic summaries must not change the existing effects event.
1706
+ }
1561
1707
  await this.core?.effects?.emit?.(`${this.name}:${_types.UnifiedBookingSalesHooks.onAvailabilityProjectionDiagnostic}`, {
1562
1708
  ...payload,
1563
1709
  registrySize: this.availabilityContextRegistry.size,
@@ -1725,6 +1871,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1725
1871
  });
1726
1872
  }
1727
1873
  const tempOrder = await super.addNewOrder();
1874
+ const logContext = this.getSolutionLogContext();
1728
1875
  if (sessionRecord) {
1729
1876
  this.store.order?.persistTempOrder();
1730
1877
  }
@@ -1735,13 +1882,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1735
1882
  await this.refreshLegacySessionCustomerDiscounts(tempOrder);
1736
1883
  }
1737
1884
  } catch (error) {
1738
- console.warn('[UnifiedBookingSales] Failed to sync authenticated order customer after addNewOrder', error);
1885
+ this.logSolutionFailure('syncAuthenticatedOrderCustomer', error, {}, logContext, 'warning');
1739
1886
  }
1740
1887
  } else if (sessionRecord) {
1741
1888
  try {
1742
1889
  await this.refreshLegacySessionCustomerDiscounts(tempOrder);
1743
1890
  } catch (error) {
1744
- console.warn('[UnifiedBookingSales] Failed to refresh cached customer discounts after addNewOrder', error);
1891
+ this.logSolutionFailure('refreshLegacySessionCustomerDiscounts', error, {}, logContext, 'warning');
1745
1892
  }
1746
1893
  }
1747
1894
  return this.store.order?.getTempOrder() || tempOrder;
@@ -1833,10 +1980,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
1833
1980
  this.otherParams.openData = injectedOpenData;
1834
1981
  this.openDataTarget = `${businessCode}+${this.getSubmitOrderSalesChannel()}`;
1835
1982
  }
1983
+ const logContext = this.getSolutionLogContext();
1836
1984
  try {
1837
1985
  await this.loadOpenDataConfig();
1838
1986
  } catch (error) {
1839
- console.warn('[UnifiedBookingSales] Invoice 模板预加载失败,使用默认配置', error);
1987
+ this.logSolutionFailure('prepareInvoiceTemplateAtSolutionReady', error, {
1988
+ fallback: 'default'
1989
+ }, logContext, 'warning');
1840
1990
  }
1841
1991
  }
1842
1992
  async loadOpenDataConfig() {
@@ -2053,6 +2203,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2053
2203
  }
2054
2204
  async fetchAllergyItemRuleConfigs(strategyModelIds) {
2055
2205
  if (!strategyModelIds.length) return [];
2206
+ const logContext = this.getSolutionLogContext();
2056
2207
  try {
2057
2208
  const response = await this.request.get('/promotion', {
2058
2209
  skip: 1,
@@ -2066,9 +2217,9 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
2066
2217
  const list = response.data.list;
2067
2218
  return normalizeItemRuleStrategyConfigs(list.map(item => item?.metadata));
2068
2219
  } catch (error) {
2069
- // this.logMethodError('fetchAllergyItemRuleConfigs', error, {
2070
- // strategyModelIds,
2071
- // });
2220
+ this.logSolutionFailure('fetchAllergyItemRuleConfigs', error, {
2221
+ strategyModelIds
2222
+ }, logContext);
2072
2223
  throw error;
2073
2224
  }
2074
2225
  }
@@ -3402,12 +3553,18 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
3402
3553
  const cachedRawResources = this.availabilityRemoteOccupancyCache.read(cacheParams);
3403
3554
  if (cachedRawResources) {
3404
3555
  if (params.useCacheOnHit) {
3556
+ const logContext = this.getSolutionLogContext();
3405
3557
  void this.refreshAvailabilityRemoteResourceQuery({
3406
3558
  timezone: params.timezone,
3407
3559
  dateRange: params.dateRange,
3408
3560
  resourceIds: normalizedResourceIds
3409
3561
  }).catch(error => {
3410
- console.warn('[UnifiedBookingSales] Remote occupancy background refresh failed', error);
3562
+ this.logSolutionFailure('refreshAvailabilityRemoteResources', error, {
3563
+ resourceCount: normalizedResourceIds.length,
3564
+ dateRange: {
3565
+ ...params.dateRange
3566
+ }
3567
+ }, logContext, 'warning');
3411
3568
  });
3412
3569
  }
3413
3570
  return cachedRawResources;
@@ -3933,6 +4090,18 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
3933
4090
  }
3934
4091
  }
3935
4092
  }
4093
+
4094
+ /** Read an existing customer selection without refreshing its clock or occupancy snapshot. */
4095
+ getCustomerSelectionProjection(contextId) {
4096
+ const context = this.getAvailabilityContextEntry(contextId);
4097
+ const projectionEntry = this.getActiveAvailabilityProjectionEntry(context);
4098
+ if (!projectionEntry) throw this.createAvailabilityFacadeError('AVAILABILITY_CONTEXT_NOT_FOUND', '所选商品上下文已关闭,请重新打开商品');
4099
+ return {
4100
+ context,
4101
+ projectionEntry,
4102
+ refreshed: false
4103
+ };
4104
+ }
3936
4105
  async ensureAvailabilityContextProjection(contextId, reason) {
3937
4106
  let retries = 0;
3938
4107
  while (retries < 3) {
@@ -4014,6 +4183,18 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4014
4183
 
4015
4184
  /** IO boundary: loads catalog, schedules, resources, occupancies, and registers one context. */
4016
4185
  async prepareAvailabilityProjection(params) {
4186
+ const logContext = this.getSolutionLogContext();
4187
+ try {
4188
+ return await this.prepareAvailabilityContext(params);
4189
+ } catch (error) {
4190
+ this.logSolutionFailure('prepareAvailabilityProjection', error, {
4191
+ productCount: params?.productIds?.length,
4192
+ resourceCount: params?.resourceIds?.length
4193
+ }, logContext);
4194
+ throw error;
4195
+ }
4196
+ }
4197
+ async prepareAvailabilityContext(params) {
4017
4198
  this.assertAvailabilityPrepareParams(params);
4018
4199
  const paramsWithDefaults = await this.resolveAvailabilityPrepareDefaults(params);
4019
4200
  const {
@@ -4082,15 +4263,19 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4082
4263
 
4083
4264
  /** Thin facade: auto-refresh on cart drift, then delegate to the pure projection query. */
4084
4265
  async queryBookingAvailability(contextId, request) {
4266
+ const customerSelectionSnapshot = request.target === 'resource' && request.customerSelectionSnapshot === true && (0, _platform.isCustomerUserPlatform)(this.otherParams?.platform);
4085
4267
  const {
4086
4268
  context,
4087
4269
  projectionEntry,
4088
4270
  refreshed
4089
- } = await this.ensureAvailabilityContextProjection(contextId, 'query_booking_availability');
4271
+ } = customerSelectionSnapshot ? this.getCustomerSelectionProjection(contextId) : await this.ensureAvailabilityContextProjection(contextId, 'query_booking_availability');
4090
4272
  this.assertContextualQueryFreshness(context, request);
4091
4273
  const strictAvailability = context.prepareParams.strictAvailability === true;
4092
4274
  const isPosAvailabilityRequest = String(this.otherParams?.platform ?? '').trim().toLowerCase() === 'pos';
4093
4275
  const result = (0, _ResourcePlanner.queryAvailabilityProjection)(projectionEntry.projection, request, {
4276
+ ...(customerSelectionSnapshot ? {
4277
+ evaluatedAt: projectionEntry.projection.meta.now
4278
+ } : {}),
4094
4279
  useExactDurationCandidateMinute: isPosAvailabilityRequest && !strictAvailability,
4095
4280
  allowExcludedScheduleDateOverride: isPosAvailabilityRequest && !strictAvailability
4096
4281
  });
@@ -4185,8 +4370,20 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4185
4370
  return (this.getTempOrder()?.bookings || []).find(booking => bookingUid && getBookingUid(booking) === bookingUid || productUid && String(booking.product_uid ?? '') === productUid);
4186
4371
  }
4187
4372
 
4188
- /** Revalidates against the latest landed occupancy cache, then mutates exactly one product line. */
4373
+ /** Customer snapshot writes defer availability to checkout; other callers retain cache revalidation. */
4189
4374
  async commitAvailabilitySelection(contextId, params) {
4375
+ const logContext = this.getSolutionLogContext();
4376
+ try {
4377
+ return await this.commitAvailabilitySelectionWithLock(contextId, params);
4378
+ } catch (error) {
4379
+ this.logSolutionFailure('commitAvailabilitySelection', error, {
4380
+ contextId,
4381
+ mode: params?.mode
4382
+ }, logContext);
4383
+ throw error;
4384
+ }
4385
+ }
4386
+ async commitAvailabilitySelectionWithLock(contextId, params) {
4190
4387
  const normalizedContextId = String(contextId || '').trim();
4191
4388
  if (!normalizedContextId) {
4192
4389
  throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', 'commitAvailabilitySelection 缺少 contextId', {
@@ -4198,8 +4395,9 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4198
4395
  if (isPartyReplacement && (!isEditingSelection || !Array.isArray(params.relatedRetailProducts))) {
4199
4396
  throw new _ResourcePlanner.AvailabilityError('INVALID_TARGET_FILTER', 'Party replacement requires edit/replace mode and the confirmed complete extras array');
4200
4397
  }
4398
+ const customerSelectionSnapshot = params.customerSelectionSnapshot === true && (0, _platform.isCustomerUserPlatform)(this.otherParams?.platform);
4201
4399
  const strictAvailability = this.availabilityContextRegistry.get(normalizedContextId)?.prepareParams.strictAvailability === true;
4202
- const hasCommitGuard = strictAvailability || isPartyReplacement || Boolean(params.availabilityCommitGuard);
4400
+ const hasCommitGuard = customerSelectionSnapshot || strictAvailability || isPartyReplacement || Boolean(params.availabilityCommitGuard);
4203
4401
  params.availabilityCommitGuard?.();
4204
4402
  // Stabilize the locally generated sale identity before taking the guard snapshot.
4205
4403
  if (hasCommitGuard) this.store.order?.ensureTempOrder?.();
@@ -4244,7 +4442,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4244
4442
  context,
4245
4443
  projectionEntry,
4246
4444
  refreshed
4247
- } = await this.ensureAvailabilityContextProjection(normalizedContextId, 'commit_precheck');
4445
+ } = customerSelectionSnapshot ? this.getCustomerSelectionProjection(normalizedContextId) : await this.ensureAvailabilityContextProjection(normalizedContextId, 'commit_precheck');
4248
4446
  if (refreshed) {
4249
4447
  throw this.createAvailabilityFacadeError('AVAILABILITY_SELECTION_STALE', 'availability context 已刷新,请重新获取候选', {
4250
4448
  contextId: normalizedContextId,
@@ -4274,7 +4472,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4274
4472
  projectionContextVersion: projectionEntry.contextVersion
4275
4473
  });
4276
4474
  }
4277
- if (projectionEntry.orderRevision !== this.getCurrentOrderRevision()) {
4475
+ if (!customerSelectionSnapshot && projectionEntry.orderRevision !== this.getCurrentOrderRevision()) {
4278
4476
  throw this.createAvailabilityFacadeError('AVAILABILITY_SELECTION_STALE', '购物车已变化,请重新获取候选', {
4279
4477
  contextId: normalizedContextId,
4280
4478
  currentContextVersion: context.activeVersion,
@@ -4324,18 +4522,22 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4324
4522
  expectedVersion: context.activeVersion,
4325
4523
  expectedRefreshNonce: context.refreshNonce,
4326
4524
  expectedLifecycleGeneration: this.availabilityLifecycleGeneration,
4327
- expectedOrderRevision: String(baseProjection.meta.orderRevision ?? '')
4525
+ expectedOrderRevision: customerSelectionSnapshot ? this.getCurrentOrderRevision() : String(baseProjection.meta.orderRevision ?? '')
4328
4526
  };
4329
4527
  const prepareParams = baseProjection.meta.prepareParams;
4330
4528
  if (!prepareParams) {
4331
4529
  throw new _ResourcePlanner.AvailabilityError('REVALIDATION_FAILED', 'projection 缺少 prepareParams,无法执行缓存重校验');
4332
4530
  }
4333
- const fallbackResources = {
4531
+ const fallbackResources = customerSelectionSnapshot ? undefined : {
4334
4532
  resources: (0, _lodashEs.cloneDeep)([...(baseProjection.resources || [])]),
4335
4533
  resourceOccupancies: (0, _lodashEs.cloneDeep)([...(baseProjection.resourceOccupancies || [])].filter(occupancy => occupancy.source !== 'cart')),
4336
4534
  includesInjectedRawOccupancies: true
4337
4535
  };
4338
- const commitSnapshot = await this.buildAvailabilityProjectionSnapshot({
4536
+ const commitSnapshot = customerSelectionSnapshot ? {
4537
+ projection: baseProjection,
4538
+ prepareParams,
4539
+ orderRevision: commitWriteGuard.expectedOrderRevision
4540
+ } : await this.buildAvailabilityProjectionSnapshot({
4339
4541
  ...this.cloneAvailabilityPrepareParams(prepareParams),
4340
4542
  editingProductLineUids: isEditingSelection && params.productLineUid ? [params.productLineUid] : []
4341
4543
  }, {
@@ -4344,7 +4546,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4344
4546
  durationCandidateAnchorAt: this.getAvailabilityDurationCandidateAnchorAt(baseProjection) || context.durationCandidateAnchorAt
4345
4547
  });
4346
4548
  const refreshedProjection = commitSnapshot.projection;
4347
- if (String(refreshedProjection.meta.orderRevision ?? '') !== String(baseProjection.meta.orderRevision ?? '')) {
4549
+ if (!customerSelectionSnapshot && String(refreshedProjection.meta.orderRevision ?? '') !== String(baseProjection.meta.orderRevision ?? '')) {
4348
4550
  await this.refreshAvailabilityContextProjection({
4349
4551
  contextId: normalizedContextId,
4350
4552
  reason: 'commit_order_revision_changed',
@@ -4365,7 +4567,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4365
4567
  const candidateDurationMinutes = getCandidateDurationMinutes(params.candidate);
4366
4568
  const candidateStartTime = getCandidateStartTime(params.candidate);
4367
4569
  const allowPosAvailabilityOverride = String(this.otherParams?.platform ?? '').trim().toLowerCase() === 'pos' && !strictAvailability;
4368
- const refreshedRanges = (0, _ResourcePlanner.getProductTimeRanges)(refreshedProjection, {
4570
+ const refreshedRanges = customerSelectionSnapshot ? [params.candidate] : (0, _ResourcePlanner.getProductTimeRanges)(refreshedProjection, {
4369
4571
  productIds: [params.candidate.productId],
4370
4572
  dateRange: {
4371
4573
  startDate: params.candidate.startAt.slice(0, 10),
@@ -4406,7 +4608,13 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4406
4608
  productId: refreshedCandidateBase.productId
4407
4609
  });
4408
4610
  }
4409
- let validation = (0, _ResourcePlanner.validateAvailabilitySelection)(refreshedProjection, {
4611
+ let validation = customerSelectionSnapshot ? acceptCustomerSelectionSnapshot({
4612
+ candidate: params.candidate,
4613
+ product,
4614
+ resources: baseProjection.resources,
4615
+ requirementSelections: params.requirementSelections,
4616
+ partySize
4617
+ }) : (0, _ResourcePlanner.validateAvailabilitySelection)(refreshedProjection, {
4410
4618
  candidate: refreshedCandidateBase,
4411
4619
  requirementSelections: params.requirementSelections,
4412
4620
  partySize,
@@ -4445,7 +4653,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4445
4653
  // Revalidation failure must leave the caller's candidate reusable. Only publish the
4446
4654
  // refreshed projection/version after candidate and resource validation has passed;
4447
4655
  // otherwise a second Confirm from the still-open modal would incorrectly become stale.
4448
- const revalidationEntry = this.storeAvailabilityProjectionEntry({
4656
+ const revalidationEntry = customerSelectionSnapshot ? projectionEntry : this.storeAvailabilityProjectionEntry({
4449
4657
  contextId: normalizedContextId,
4450
4658
  prepareParams: commitSnapshot.prepareParams,
4451
4659
  prepareKey: context.prepareKey,
@@ -4454,7 +4662,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4454
4662
  incrementVersion: true
4455
4663
  });
4456
4664
  const revalidatedContext = this.getAvailabilityContextEntry(normalizedContextId);
4457
- await this.emitAvailabilityDiagnostic({
4665
+ if (!customerSelectionSnapshot) await this.emitAvailabilityDiagnostic({
4458
4666
  action: 'refresh',
4459
4667
  contextId: normalizedContextId,
4460
4668
  contextVersion: revalidatedContext.activeVersion,
@@ -4469,7 +4677,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4469
4677
  expectedVersion: revalidatedContext.activeVersion,
4470
4678
  expectedRefreshNonce: revalidatedContext.refreshNonce,
4471
4679
  expectedLifecycleGeneration: this.availabilityLifecycleGeneration,
4472
- expectedOrderRevision: revalidationEntry.orderRevision
4680
+ expectedOrderRevision: customerSelectionSnapshot ? commitWriteGuard.expectedOrderRevision : revalidationEntry.orderRevision
4473
4681
  };
4474
4682
  const refreshedCandidate = this.decorateAvailabilityCandidate(normalizedContextId, revalidatedContext.activeVersion, refreshedCandidateBase);
4475
4683
  // Order may await line/runtime setup. Its guarded transaction invokes this
@@ -4480,7 +4688,7 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
4480
4688
  if (!availabilityCommitTargetGuard()) {
4481
4689
  throw this.createAvailabilityFacadeError('AVAILABILITY_SELECTION_STALE', '预约加购期间订单或业务已变化');
4482
4690
  }
4483
- if (!strictAvailability) return;
4691
+ if (customerSelectionSnapshot || !strictAvailability) return;
4484
4692
  const currentValidation = (0, _ResourcePlanner.validateAvailabilitySelection)(refreshedProjection, {
4485
4693
  candidate: refreshedCandidateBase,
4486
4694
  requirementSelections: params.requirementSelections,
@@ -145,6 +145,8 @@ export type ContextualAvailabilityQuery = Omit<Extract<AvailabilityQuery, {
145
145
  target: 'resource';
146
146
  }>, 'selectedRanges'> & {
147
147
  selectedRanges: ContextualProductTimeRange[];
148
+ /** PC/H5 only: retain the already-selected time while choosing resources in this snapshot. */
149
+ customerSelectionSnapshot?: boolean;
148
150
  });
149
151
  export type ContextualTimeAvailabilityItem = Omit<TimeAvailabilityItem, keyof ProductTimeRange> & ContextualProductTimeRange;
150
152
  export interface ContextualTimeAvailabilityGroup extends Omit<TimeAvailabilityGroup, 'times'> {
@@ -210,6 +212,8 @@ export interface UnifiedBookingSalesAddRetailProductParams {
210
212
  }
211
213
  export interface ContextualCommitAvailabilitySelectionParams {
212
214
  mode: 'add' | 'edit' | 'replace';
215
+ /** PC/H5 only: write the completed UI selection without re-querying availability; checkout is authoritative. */
216
+ customerSelectionSnapshot?: boolean;
213
217
  /** Local UI intent guard, checked again immediately before the Order mutation. */
214
218
  availabilityCommitGuard?: () => void;
215
219
  productLineUid?: string;