@pisell/pisellos 0.10.90 → 0.10.91

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 (227) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +74 -7
  3. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  4. package/dist/model/strategy/adapter/itemRule/evaluator.js +13 -0
  5. package/dist/model/strategy/adapter/itemRule/type.d.ts +40 -1
  6. package/dist/model/strategy/adapter/itemRule/type.js +10 -0
  7. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  8. package/dist/model/strategy/adapter/promotion/evaluator.js +103 -112
  9. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  10. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  11. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  12. package/dist/modules/BookingContext/utils/index.js +1 -0
  13. package/dist/modules/BookingContext/utils/productExtend.d.ts +21 -0
  14. package/dist/modules/BookingContext/utils/productExtend.js +132 -33
  15. package/dist/modules/BookingContext/utils/resources.js +1 -1
  16. package/dist/modules/Cart/index.js +4 -3
  17. package/dist/modules/Cart/types.d.ts +2 -0
  18. package/dist/modules/Cart/utils/cartProduct.d.ts +3 -1
  19. package/dist/modules/Cart/utils/cartProduct.js +59 -32
  20. package/dist/modules/Date/index.d.ts +1 -1
  21. package/dist/modules/Date/index.js +60 -14
  22. package/dist/modules/Date/types.d.ts +5 -0
  23. package/dist/modules/OpenData/salesSettings.js +1 -1
  24. package/dist/modules/OpenData/types.d.ts +9 -0
  25. package/dist/modules/OpenData/utils.d.ts +1 -1
  26. package/dist/modules/OpenData/utils.js +3 -2
  27. package/dist/modules/Order/index.d.ts +22 -7
  28. package/dist/modules/Order/index.js +1565 -1161
  29. package/dist/modules/Order/localEftposState.d.ts +13 -0
  30. package/dist/modules/Order/localEftposState.js +39 -0
  31. package/dist/modules/Order/types.d.ts +33 -11
  32. package/dist/modules/Order/types.js +2 -2
  33. package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
  34. package/dist/modules/Order/unpaidAmountGap.js +72 -0
  35. package/dist/modules/Order/utils.d.ts +4 -1
  36. package/dist/modules/Order/utils.js +75 -52
  37. package/dist/modules/Payment/walletpass.js +32 -6
  38. package/dist/modules/Product/types.d.ts +16 -0
  39. package/dist/modules/ProductList/index.js +1 -1
  40. package/dist/modules/ResourcePlanner/planner.d.ts +2 -0
  41. package/dist/modules/ResourcePlanner/planner.js +383 -24
  42. package/dist/modules/ResourcePlanner/types.d.ts +42 -0
  43. package/dist/modules/Rules/index.js +86 -54
  44. package/dist/modules/Schedule/index.d.ts +7 -1
  45. package/dist/modules/Schedule/index.js +155 -39
  46. package/dist/modules/Schedule/types.d.ts +2 -0
  47. package/dist/modules/bookingReadValidation.d.ts +6 -0
  48. package/dist/modules/bookingReadValidation.js +72 -0
  49. package/dist/plugins/request.d.ts +2 -0
  50. package/dist/server/index.d.ts +9 -0
  51. package/dist/server/index.js +1928 -1462
  52. package/dist/server/modules/form/index.d.ts +19 -0
  53. package/dist/server/modules/form/index.js +205 -0
  54. package/dist/server/modules/form/types.d.ts +13 -0
  55. package/dist/server/modules/form/types.js +3 -0
  56. package/dist/server/modules/index.d.ts +3 -0
  57. package/dist/server/modules/index.js +4 -0
  58. package/dist/server/modules/order/index.d.ts +21 -0
  59. package/dist/server/modules/order/index.js +1399 -831
  60. package/dist/server/modules/order/types.d.ts +3 -0
  61. package/dist/server/modules/order/utils/filterOrders.js +20 -0
  62. package/dist/server/modules/products/index.d.ts +28 -7
  63. package/dist/server/modules/products/index.js +1295 -769
  64. package/dist/server/modules/products/replication.d.ts +8 -0
  65. package/dist/server/modules/products/replication.js +69 -0
  66. package/dist/server/modules/products/types.d.ts +12 -1
  67. package/dist/server/modules/products/types.js +4 -0
  68. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  69. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  70. package/dist/shared/receipt/small-ticket.d.ts +1 -0
  71. package/dist/shared/receipt/small-ticket.js +58 -26
  72. package/dist/shared/receipt/templateVisibility.d.ts +3 -0
  73. package/dist/shared/receipt/templateVisibility.js +6 -2
  74. package/dist/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  75. package/dist/solution/BaseSales/fulfillmentItemRules.js +750 -0
  76. package/dist/solution/BaseSales/index.d.ts +22 -6
  77. package/dist/solution/BaseSales/index.js +1881 -1347
  78. package/dist/solution/BaseSales/pickupTiming.d.ts +4 -0
  79. package/dist/solution/BaseSales/pickupTiming.js +35 -8
  80. package/dist/solution/BaseSales/types.d.ts +4 -0
  81. package/dist/solution/BaseSales/types.js +1 -0
  82. package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  83. package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
  84. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  85. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
  86. package/dist/solution/BookingByStep/index.d.ts +18 -2
  87. package/dist/solution/BookingByStep/index.js +681 -361
  88. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  89. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  90. package/dist/solution/BookingTicket/index.d.ts +6 -0
  91. package/dist/solution/BookingTicket/index.js +666 -593
  92. package/dist/solution/BookingTicket/types.d.ts +1 -1
  93. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  94. package/dist/solution/BookingTicket/utils/addProductDecision.js +35 -8
  95. package/dist/solution/BookingTicket/utils/redeemArrival.d.ts +3 -3
  96. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  97. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  98. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +58 -94
  99. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  100. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +33 -62
  101. package/dist/solution/OrderInvoicePreview/index.js +4 -3
  102. package/dist/solution/Sales/index.js +1 -1
  103. package/dist/solution/ScanOrder/index.d.ts +2 -0
  104. package/dist/solution/ScanOrder/index.js +230 -97
  105. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  106. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  107. package/dist/solution/ScanOrder/types.d.ts +3 -0
  108. package/dist/solution/UnifiedBookingSales/index.d.ts +42 -10
  109. package/dist/solution/UnifiedBookingSales/index.js +2493 -1496
  110. package/dist/solution/UnifiedBookingSales/salesSettings.js +1 -1
  111. package/dist/solution/UnifiedBookingSales/types.d.ts +20 -5
  112. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  113. package/dist/utils/pos-receipt-auto-print.js +14 -0
  114. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +3 -1
  115. package/lib/model/strategy/adapter/itemRule/adapter.js +54 -4
  116. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +3 -1
  117. package/lib/model/strategy/adapter/itemRule/evaluator.js +9 -0
  118. package/lib/model/strategy/adapter/itemRule/type.d.ts +40 -1
  119. package/lib/model/strategy/adapter/itemRule/type.js +10 -0
  120. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +2 -1
  121. package/lib/model/strategy/adapter/promotion/evaluator.js +22 -21
  122. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  123. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  124. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  125. package/lib/modules/BookingContext/utils/index.js +11 -0
  126. package/lib/modules/BookingContext/utils/productExtend.d.ts +21 -0
  127. package/lib/modules/BookingContext/utils/productExtend.js +104 -5
  128. package/lib/modules/BookingContext/utils/resources.js +1 -1
  129. package/lib/modules/Cart/index.js +4 -2
  130. package/lib/modules/Cart/types.d.ts +2 -0
  131. package/lib/modules/Cart/utils/cartProduct.d.ts +3 -1
  132. package/lib/modules/Cart/utils/cartProduct.js +39 -20
  133. package/lib/modules/Date/index.d.ts +1 -1
  134. package/lib/modules/Date/index.js +28 -5
  135. package/lib/modules/Date/types.d.ts +5 -0
  136. package/lib/modules/OpenData/salesSettings.js +1 -1
  137. package/lib/modules/OpenData/types.d.ts +9 -0
  138. package/lib/modules/OpenData/utils.d.ts +1 -1
  139. package/lib/modules/OpenData/utils.js +3 -2
  140. package/lib/modules/Order/index.d.ts +22 -7
  141. package/lib/modules/Order/index.js +457 -174
  142. package/lib/modules/Order/localEftposState.d.ts +13 -0
  143. package/lib/modules/Order/localEftposState.js +44 -0
  144. package/lib/modules/Order/types.d.ts +33 -11
  145. package/lib/modules/Order/types.js +2 -2
  146. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  147. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  148. package/lib/modules/Order/utils.d.ts +4 -1
  149. package/lib/modules/Order/utils.js +29 -3
  150. package/lib/modules/Payment/walletpass.js +23 -1
  151. package/lib/modules/Product/types.d.ts +16 -0
  152. package/lib/modules/ProductList/index.js +1 -1
  153. package/lib/modules/ResourcePlanner/planner.d.ts +2 -0
  154. package/lib/modules/ResourcePlanner/planner.js +299 -9
  155. package/lib/modules/ResourcePlanner/types.d.ts +42 -0
  156. package/lib/modules/Rules/index.js +32 -3
  157. package/lib/modules/Schedule/index.d.ts +7 -1
  158. package/lib/modules/Schedule/index.js +68 -4
  159. package/lib/modules/Schedule/types.d.ts +2 -0
  160. package/lib/modules/bookingReadValidation.d.ts +6 -0
  161. package/lib/modules/bookingReadValidation.js +56 -0
  162. package/lib/plugins/request.d.ts +2 -0
  163. package/lib/server/index.d.ts +9 -0
  164. package/lib/server/index.js +279 -30
  165. package/lib/server/modules/form/index.d.ts +19 -0
  166. package/lib/server/modules/form/index.js +73 -0
  167. package/lib/server/modules/form/types.d.ts +13 -0
  168. package/lib/server/modules/form/types.js +9 -0
  169. package/lib/server/modules/index.d.ts +3 -0
  170. package/lib/server/modules/index.js +15 -1
  171. package/lib/server/modules/order/index.d.ts +21 -0
  172. package/lib/server/modules/order/index.js +344 -35
  173. package/lib/server/modules/order/types.d.ts +3 -0
  174. package/lib/server/modules/order/utils/filterOrders.js +18 -0
  175. package/lib/server/modules/products/index.d.ts +28 -7
  176. package/lib/server/modules/products/index.js +224 -62
  177. package/lib/server/modules/products/replication.d.ts +8 -0
  178. package/lib/server/modules/products/replication.js +30 -0
  179. package/lib/server/modules/products/types.d.ts +12 -1
  180. package/lib/server/modules/products/types.js +3 -0
  181. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  182. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  183. package/lib/shared/receipt/small-ticket.d.ts +1 -0
  184. package/lib/shared/receipt/small-ticket.js +53 -25
  185. package/lib/shared/receipt/templateVisibility.d.ts +3 -0
  186. package/lib/shared/receipt/templateVisibility.js +6 -2
  187. package/lib/solution/BaseSales/fulfillmentItemRules.d.ts +27 -0
  188. package/lib/solution/BaseSales/fulfillmentItemRules.js +259 -0
  189. package/lib/solution/BaseSales/index.d.ts +22 -6
  190. package/lib/solution/BaseSales/index.js +347 -59
  191. package/lib/solution/BaseSales/pickupTiming.d.ts +4 -0
  192. package/lib/solution/BaseSales/pickupTiming.js +24 -3
  193. package/lib/solution/BaseSales/types.d.ts +4 -0
  194. package/lib/solution/BaseSales/types.js +1 -0
  195. package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
  196. package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
  197. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
  198. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  199. package/lib/solution/BookingByStep/index.d.ts +18 -2
  200. package/lib/solution/BookingByStep/index.js +229 -17
  201. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  202. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  203. package/lib/solution/BookingTicket/index.d.ts +6 -0
  204. package/lib/solution/BookingTicket/index.js +40 -5
  205. package/lib/solution/BookingTicket/types.d.ts +1 -1
  206. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +2 -1
  207. package/lib/solution/BookingTicket/utils/addProductDecision.js +34 -4
  208. package/lib/solution/BookingTicket/utils/redeemArrival.d.ts +3 -3
  209. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  210. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  211. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +2 -14
  212. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +1 -3
  213. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +17 -34
  214. package/lib/solution/OrderInvoicePreview/index.js +1 -0
  215. package/lib/solution/Sales/index.js +1 -1
  216. package/lib/solution/ScanOrder/index.d.ts +2 -0
  217. package/lib/solution/ScanOrder/index.js +131 -22
  218. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  219. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  220. package/lib/solution/ScanOrder/types.d.ts +3 -0
  221. package/lib/solution/UnifiedBookingSales/index.d.ts +42 -10
  222. package/lib/solution/UnifiedBookingSales/index.js +717 -144
  223. package/lib/solution/UnifiedBookingSales/salesSettings.js +1 -1
  224. package/lib/solution/UnifiedBookingSales/types.d.ts +20 -5
  225. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  226. package/lib/utils/pos-receipt-auto-print.js +13 -0
  227. package/package.json +1 -1
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.createAvailabilityProjection = createAvailabilityProjection;
7
+ exports.getDurationBusinessDate = getDurationBusinessDate;
7
8
  exports.getProductTimeRanges = getProductTimeRanges;
8
9
  exports.queryAvailabilityProjection = queryAvailabilityProjection;
9
10
  exports.validateAvailabilitySelection = validateAvailabilitySelection;
@@ -162,8 +163,11 @@ function resolveCutOffPolicyIssue(policy) {
162
163
  return null;
163
164
  }
164
165
  function addLeadWindow(base, unit, unitType, _timezoneName) {
165
- // Calendar-day lead times retain the current local hour, minute and second.
166
- if (unitType === 'days') return (0, _localClock.addLocalCalendarDays)(base, unit);
166
+ if (unitType === 'days') {
167
+ const leadDate = (0, _localClock.addLocalCalendarDays)(base, unit);
168
+ // Positive day lead times start at midnight; zero days keeps the current-time boundary.
169
+ return Math.trunc(unit) > 0 ? (0, _localClock.localDateToScalarStart)((0, _localClock.formatLocalDate)(leadDate)) : leadDate;
170
+ }
167
171
  if (unitType === 'hours') return (0, _localClock.addLocalHours)(base, unit);
168
172
  return (0, _localClock.addLocalMinutes)(base, unit);
169
173
  }
@@ -221,6 +225,16 @@ function isCandidateFromExcludedScheduleDate(params) {
221
225
  }
222
226
  return getSessionRangesForProduct(projection, product, candidateDateRange, true).some(range => getProductTimeRangeIdentity(range) === candidateIdentity);
223
227
  }
228
+ function resolveRememberedDurationRange(product, value, timezoneName) {
229
+ if (value === undefined) return null;
230
+ const range = normalizeAbsoluteRange(value, timezoneName);
231
+ if (!range || range.end <= range.start) {
232
+ throw availabilityError('INVALID_TARGET_FILTER', '记忆时间必须包含有效且递增的开始和结束时间');
233
+ }
234
+ if (product.kind !== 'duration') return null;
235
+ if (!product.isFlexibleDuration && (!Number.isFinite(product.durationMinutes) || range.end - range.start !== Number(product.durationMinutes) * 60000)) return null;
236
+ return range;
237
+ }
224
238
  function evaluateCandidateTimeGate(params) {
225
239
  const {
226
240
  projection,
@@ -251,6 +265,18 @@ function evaluateCandidateTimeGate(params) {
251
265
  };
252
266
  }
253
267
  const policy = product.cutOffPolicy;
268
+ // Current duration items can be shown outside business hours. Their real
269
+ // interval must remain unavailable, including products with no resource groups.
270
+ if (evaluationContext.useDurationTimeGrid && product.kind === 'duration' && !projection.meta.defaults.operatingHours.windows.some(window => {
271
+ const range = normalizeAbsoluteRange(window);
272
+ return range && contains(range, candidateRange);
273
+ })) {
274
+ return {
275
+ status: 'unavailable',
276
+ reasonCodes: ['outside_operating_hours'],
277
+ conflictCode: 'booking_cutoff'
278
+ };
279
+ }
254
280
  if (!policy) return null;
255
281
  if (resolveCutOffPolicyIssue(policy)) {
256
282
  return {
@@ -282,13 +308,17 @@ function evaluateCandidateTimeGate(params) {
282
308
  };
283
309
  }
284
310
  if (policy.type === 'before_start') {
311
+ const rememberedRange = resolveRememberedDurationRange(product, evaluationContext.rememberedTimeByProductId?.[String(product.id)], timezoneName);
312
+ // Only the exact order-scoped interval may retain its start after this
313
+ // cutoff. The end/past and operating-window gates above still apply.
314
+ if (rememberedRange?.start === candidateRange.start && rememberedRange.end === candidateRange.end) return null;
285
315
  // POS fixed-duration candidates use the context's stable opening-minute
286
316
  // anchor. Keep that anchored range selectable while it is still active;
287
317
  // otherwise a minute refresh turns it into 0 capacity and incorrectly
288
318
  // advances a create flow to the next slot. The earlier `past` gate still
289
319
  // rejects the anchor once its booking range has ended.
290
- const isActivePosDurationAnchor = evaluationContext.useExactDurationCandidateMinute && product.kind === 'duration' && !product.isFlexibleDuration && evaluationContext.durationCandidateAnchorAtMs === candidateRange.start;
291
- const usesMinutePrecision = product.isFlexibleDuration || evaluationContext.useExactDurationCandidateMinute && product.kind === 'duration';
320
+ const isActivePosDurationAnchor = evaluationContext.useExactDurationCandidateMinute && !evaluationContext.enforceSaleCutoff && product.kind === 'duration' && !product.isFlexibleDuration && evaluationContext.durationCandidateAnchorAtMs === candidateRange.start;
321
+ const usesMinutePrecision = product.isFlexibleDuration || evaluationContext.useDurationTimeGrid || evaluationContext.useExactDurationCandidateMinute && product.kind === 'duration';
292
322
  const hasNotReachedStart = isActivePosDurationAnchor || (usesMinutePrecision ? floorToMinute(now) <= candidateRange.start : now < candidateRange.start);
293
323
  if (hasNotReachedStart) return null;
294
324
  return {
@@ -490,11 +520,34 @@ function normalizeOperatingHours(params) {
490
520
  }));
491
521
  const windows = normalizeWindows(sourceWindows);
492
522
  const excludedWindows = normalizeWindows(params.input?.excludedWindows || []);
523
+ // Keep original dates and opening anchors separately: the availability
524
+ // windows below may be clipped at midnight or merged without segment identity.
525
+ const periodMap = new Map();
526
+ const originalPeriods = params.input?.businessPeriods || [...sourceWindows, ...(params.input?.excludedWindows || [])].map(window => ({
527
+ businessDate: window.businessDate || window.startAt.slice(0, 10),
528
+ startAt: window.openingAnchorAt || window.startAt,
529
+ endAt: window.endAt
530
+ }));
531
+ originalPeriods.forEach(period => {
532
+ const range = normalizeAbsoluteRange(period);
533
+ if (!range) return;
534
+ const previous = periodMap.get(period.businessDate);
535
+ periodMap.set(period.businessDate, {
536
+ start: previous ? Math.min(previous.start, range.start) : range.start,
537
+ end: previous ? Math.max(previous.end, range.end) : range.end
538
+ });
539
+ });
540
+ const businessPeriods = Array.from(periodMap, ([businessDate, range]) => ({
541
+ businessDate,
542
+ startAt: formatDateTime(range.start, params.timezoneName, params.fixedOffsetMinutes),
543
+ endAt: formatDateTime(range.end, params.timezoneName, params.fixedOffsetMinutes)
544
+ })).sort((left, right) => left.startAt.localeCompare(right.startAt));
493
545
  return {
494
546
  source: params.input?.source || params.fallbackSource,
495
547
  scheduleIds: uniqById(params.input?.scheduleIds || []),
496
548
  missingScheduleIds: uniqById(params.input?.missingScheduleIds || []),
497
549
  windows,
550
+ businessPeriods,
498
551
  ...(excludedWindows.length > 0 ? {
499
552
  excludedWindows
500
553
  } : {})
@@ -997,6 +1050,181 @@ function createDurationTimeRangeWithEnd(product, start, bookingEnd, projection,
997
1050
  scheduleRefs: []
998
1051
  };
999
1052
  }
1053
+
1054
+ /** Resolve the label without changing the real calendar timestamp. */
1055
+ function getDurationBusinessDate(projection, startAt) {
1056
+ const start = toDateTime(startAt);
1057
+ const periods = projection.meta.defaults.operatingHours.businessPeriods || [];
1058
+ const period = [...periods].reverse().find(item => {
1059
+ const range = normalizeAbsoluteRange(item);
1060
+ return range && range.start <= start && start < range.end;
1061
+ });
1062
+ return period?.businessDate || startAt.slice(0, 10);
1063
+ }
1064
+ function getRequestedProductRange(projection, product, request, runtimeOptions, fixedOffsetMinutes) {
1065
+ const range = request.requestedRangesByProductId?.[String(product.id)];
1066
+ if (!runtimeOptions.allowRequestedRanges || !range || product.kind !== 'duration' && product.kind !== 'session') return [];
1067
+ const start = toDateTime(range.startAt);
1068
+ const end = toDateTime(range.endAt);
1069
+ if (!Number.isFinite(start) || !Number.isFinite(end) || !Number.isInteger((end - start) / 60000) || end <= start) {
1070
+ throw availabilityError('INVALID_TARGET_FILTER', '手工预约范围必须包含有效起止时间和正整数分钟时长');
1071
+ }
1072
+ const candidate = createDurationTimeRangeWithEnd(product, start, end, projection, fixedOffsetMinutes);
1073
+ candidate.businessDate = getDurationBusinessDate(projection, candidate.startAt);
1074
+ assertRangesWithinProjection(projection, [candidate]);
1075
+ return [candidate];
1076
+ }
1077
+ function getAlignedDurationRanges(params) {
1078
+ const {
1079
+ projection,
1080
+ product,
1081
+ request,
1082
+ runtimeOptions,
1083
+ dateRange,
1084
+ operatingRanges,
1085
+ baseRanges,
1086
+ resourceWindowIndex,
1087
+ fixedOffsetMinutes
1088
+ } = params;
1089
+ const step = projection.meta.defaults.slotStepMinutes;
1090
+ const now = floorToMinute(toDateTime(runtimeOptions.evaluatedAt || projection.meta.durationCandidateAnchorAt));
1091
+ if (!Number.isFinite(now)) throw availabilityError('INVALID_TARGET_FILTER', 'evaluatedAt 必须是有效时间');
1092
+ const nowAt = formatDateTime(now, projection.meta.timezone, fixedOffsetMinutes);
1093
+ const currentBusinessDate = getDurationBusinessDate(projection, nowAt);
1094
+ const inRequestedDays = date => date >= dateRange.startDate && date <= dateRange.endDate;
1095
+ const periods = (projection.meta.defaults.operatingHours.businessPeriods || []).filter(period => inRequestedDays(period.businessDate));
1096
+ // A prepared month includes tomorrow's windows too; the single-day UI must
1097
+ // receive the selected business cycle's end, not tomorrow's closing time.
1098
+ const operatingEndAt = dateRange.startDate === dateRange.endDate && periods.length ? periods.reduce((latest, period) => period.endAt > latest ? period.endAt : latest, periods[0].endAt) : undefined;
1099
+ const ranges = [];
1100
+ const duration = resolveRequestedDurationMinutes(product, request);
1101
+ const addRange = (start, end, businessDate) => {
1102
+ if (end <= start) return;
1103
+ const candidate = createDurationTimeRangeWithEnd(product, start, end, projection, fixedOffsetMinutes);
1104
+ candidate.businessDate = businessDate || getDurationBusinessDate(projection, candidate.startAt);
1105
+ if (inRequestedDays(candidate.businessDate)) ranges.push(candidate);
1106
+ };
1107
+ // A flexible end comes from resources that actually cover this exact start,
1108
+ // never from the next future window. Keep alternative real ends separate.
1109
+ const flexibleEnds = start => {
1110
+ const operating = operatingRanges.find(range => range.start <= start && start < range.end);
1111
+ if (!operating) return [];
1112
+ const businessDate = getDurationBusinessDate(projection, formatDateTime(start, projection.meta.timezone, fixedOffsetMinutes));
1113
+ const period = projection.meta.defaults.operatingHours.businessPeriods?.find(item => item.businessDate === businessDate);
1114
+ const operatingEnd = Math.min(operating.end, period ? toDateTime(period.endAt) : operating.end);
1115
+ const requiredGroups = (product.requirementGroups || []).filter(group => group.required !== false);
1116
+ const groups = requiredGroups.map(group => projection.resources.filter(resource => matchesRequirementGroup(group, resource, product, request.partySize)).filter(resource => !request.resourceIds?.length || request.resourceIds.some(id => sameId(id, resource.id))).flatMap(resource => (resourceWindowIndex.get(String(resource.id)) || []).filter(range => range.start <= start && start < range.end).map(range => Math.min(range.end, operatingEnd))));
1117
+ if (groups.some(ends => ends.length === 0)) return [];
1118
+ if (!groups.length) return [operatingEnd];
1119
+ return Array.from(new Set(groups.flat())).filter(end => groups.every(ends => ends.some(availableEnd => availableEnd >= end))).sort((left, right) => left - right);
1120
+ };
1121
+ if (product.isFlexibleDuration) {
1122
+ // Preserve the existing continuous-window UI, with the business-day label.
1123
+ periods.forEach(period => {
1124
+ const periodRange = normalizeAbsoluteRange(period);
1125
+ baseRanges.forEach(range => {
1126
+ const start = Math.max(range.start, periodRange.start, now);
1127
+ const end = Math.min(range.end, periodRange.end);
1128
+ if (start < end) addRange(start, end, period.businessDate);
1129
+ });
1130
+ });
1131
+ } else {
1132
+ periods.forEach(period => {
1133
+ const periodRange = normalizeAbsoluteRange(period);
1134
+ const anchor = 60 % step === 0 ? toDateStart(period.businessDate) : periodRange.start;
1135
+ baseRanges.forEach(range => {
1136
+ const lower = Math.max(range.start, periodRange.start, now);
1137
+ const upper = Math.min(range.end, periodRange.end);
1138
+ let cursor = anchor + Math.ceil((lower - anchor) / (step * 60000)) * step * 60000;
1139
+ for (; cursor + duration * 60000 <= upper; cursor += step * 60000) {
1140
+ addRange(cursor, cursor + duration * 60000, period.businessDate);
1141
+ }
1142
+ });
1143
+ });
1144
+ }
1145
+ let unavailableCurrentTime;
1146
+ if (inRequestedDays(currentBusinessDate)) {
1147
+ if (product.isFlexibleDuration) {
1148
+ const ends = flexibleEnds(now);
1149
+ ends.forEach(end => addRange(now, end, currentBusinessDate));
1150
+ if (!ends.length) {
1151
+ unavailableCurrentTime = {
1152
+ productId: product.id,
1153
+ startAt: nowAt,
1154
+ date: formatDate(now),
1155
+ businessDate: currentBusinessDate,
1156
+ startTime: formatTime(now),
1157
+ status: 'unavailable',
1158
+ reasonCodes: [operatingRanges.some(range => range.start <= now && now < range.end) ? 'outside_resource_window' : 'outside_operating_hours']
1159
+ };
1160
+ }
1161
+ } else {
1162
+ // Even outside a working window the fixed product has a real end. Query
1163
+ // reports unavailable; POS manual capabilities remain a separate policy.
1164
+ addRange(now, now + duration * 60000, currentBusinessDate);
1165
+ }
1166
+ }
1167
+ const rememberedAt = request.rememberedStartAtByProductId?.[String(product.id)];
1168
+ if (rememberedAt !== undefined) {
1169
+ const start = toDateTime(rememberedAt);
1170
+ if (!Number.isFinite(start)) throw availabilityError('INVALID_TARGET_FILTER', '记忆开始时间必须是完整日期时间');
1171
+ if (product.isFlexibleDuration) {
1172
+ flexibleEnds(start).forEach(end => addRange(start, end));
1173
+ } else {
1174
+ addRange(start, start + duration * 60000);
1175
+ }
1176
+ }
1177
+ const rememberedRange = resolveRememberedDurationRange(product, request.rememberedTimeByProductId?.[String(product.id)], projection.meta.timezone);
1178
+ if (rememberedRange && baseRanges.some(range => contains(range, rememberedRange))) {
1179
+ // Never extend a remembered flexible interval when the resource now has a
1180
+ // later closing time, or rebuild a fixed interval after its duration changed.
1181
+ addRange(rememberedRange.start, rememberedRange.end);
1182
+ }
1183
+ const editingAt = request.editingStartAtByProductId?.[String(product.id)];
1184
+ if (editingAt !== undefined) {
1185
+ const start = toDateTime(editingAt);
1186
+ const editingDuration = Number(request.durationMinutesByProductId?.[String(product.id)]);
1187
+ if (!Number.isFinite(start) || !Number.isInteger(editingDuration) || editingDuration <= 0) {
1188
+ throw availabilityError('INVALID_TARGET_FILTER', '编辑时间必须包含完整开始日期时间和明确的正整数时长');
1189
+ }
1190
+ // Editing restores the original interval, including its actual overnight
1191
+ // date. It neither adopts the current grid nor recomputes a flexible end.
1192
+ if (request.allowOutsideOperatingHoursForRequestedStartTimes || operatingRanges.some(range => range.start <= start && start < range.end)) {
1193
+ addRange(start, addMinutesZoned(start, editingDuration, projection.meta.timezone));
1194
+ }
1195
+ }
1196
+
1197
+ // Explicit custom input keeps its existing start + requested duration
1198
+ // semantics. Remembered input above must never use this default-30 path.
1199
+ if (dateRange.startDate === dateRange.endDate) {
1200
+ resolveRequestedDurationStartTimes(product, request).forEach(startTime => {
1201
+ const sameDayStart = toDateTimeInDate(dateRange.startDate, startTime);
1202
+ const period = periods.find(item => item.businessDate === dateRange.startDate);
1203
+ const periodRange = period ? normalizeAbsoluteRange(period) : null;
1204
+ const nextDayStart = (0, _localClock.addLocalCalendarDays)(sameDayStart, 1);
1205
+ // HH:mm is entered within a selected business day, whose early hours
1206
+ // may belong to the next calendar day. Do not move other out-of-hours
1207
+ // manual input to tomorrow merely because the business closes overnight.
1208
+ const start = periodRange && !(periodRange.start <= sameDayStart && sameDayStart < periodRange.end) && periodRange.start <= nextDayStart && nextDayStart < periodRange.end ? nextDayStart : sameDayStart;
1209
+ if (request.allowOutsideOperatingHoursForRequestedStartTimes || operatingRanges.some(range => range.start <= start && start < range.end)) {
1210
+ addRange(start, start + duration * 60000);
1211
+ }
1212
+ });
1213
+ }
1214
+ return {
1215
+ productId: product.id,
1216
+ title: product.title,
1217
+ kind: product.kind,
1218
+ slotStepMinutes: step,
1219
+ ...(operatingEndAt ? {
1220
+ operatingEndAt
1221
+ } : {}),
1222
+ ranges: dedupeProductRanges(ranges),
1223
+ ...(unavailableCurrentTime ? {
1224
+ unavailableCurrentTime
1225
+ } : {})
1226
+ };
1227
+ }
1000
1228
  function getProductTimeRanges(projection, request = {}, runtimeOptions = {}) {
1001
1229
  const normalizedPartySize = normalizePartySize(request.partySize);
1002
1230
  const dateRange = resolveProjectionDateRange(projection, request.dateRange);
@@ -1006,6 +1234,16 @@ function getProductTimeRanges(projection, request = {}, runtimeOptions = {}) {
1006
1234
  const resourceWindowIndex = buildResourceWindowIndex(projection, allowExcludedScheduleDateOverride);
1007
1235
  const filteredProductIdSet = request.productIds?.length ? new Set(request.productIds.map(String)) : null;
1008
1236
  return projection.products.filter(product => !filteredProductIdSet || filteredProductIdSet.has(String(product.id))).map(product => {
1237
+ const requestedRanges = getRequestedProductRange(projection, product, request, runtimeOptions, fixedOffsetMinutes);
1238
+ if (requestedRanges.length > 0) {
1239
+ return {
1240
+ productId: product.id,
1241
+ title: product.title,
1242
+ kind: product.kind,
1243
+ slotStepMinutes,
1244
+ ranges: dedupeProductRanges(requestedRanges)
1245
+ };
1246
+ }
1009
1247
  if (product.kind === 'normal') {
1010
1248
  return {
1011
1249
  productId: product.id,
@@ -1049,6 +1287,19 @@ function getProductTimeRanges(projection, request = {}, runtimeOptions = {}) {
1049
1287
  includeExcludedWindows: allowExcludedScheduleDateOverride
1050
1288
  })).reduce((current, ranges) => current === null ? ranges : intersectRangeLists(current, ranges), null) || [] : null;
1051
1289
  const baseRanges = resourceRanges === null ? operatingRanges : intersectRangeLists(resourceRanges, operatingRanges);
1290
+ if (runtimeOptions.useDurationTimeGrid) {
1291
+ return getAlignedDurationRanges({
1292
+ projection,
1293
+ product,
1294
+ request,
1295
+ runtimeOptions,
1296
+ dateRange,
1297
+ operatingRanges,
1298
+ baseRanges,
1299
+ resourceWindowIndex,
1300
+ fixedOffsetMinutes
1301
+ });
1302
+ }
1052
1303
  const durationMinutes = resolveRequestedDurationMinutes(product, request);
1053
1304
  const flexibleStartAt = (() => {
1054
1305
  if (!product.isFlexibleDuration) return undefined;
@@ -1270,7 +1521,10 @@ function buildEvaluationContext(params) {
1270
1521
  selectionsByGroupKey,
1271
1522
  useExactDurationCandidateMinute: params.useExactDurationCandidateMinute === true,
1272
1523
  durationCandidateAnchorAtMs: Number.isFinite(durationCandidateAnchorAt) ? floorToMinute(durationCandidateAnchorAt) : null,
1273
- allowExcludedScheduleDateOverride: params.allowExcludedScheduleDateOverride === true
1524
+ allowExcludedScheduleDateOverride: params.allowExcludedScheduleDateOverride === true,
1525
+ useDurationTimeGrid: params.useDurationTimeGrid === true,
1526
+ enforceSaleCutoff: params.enforceSaleCutoff === true,
1527
+ rememberedTimeByProductId: params.rememberedTimeByProductId
1274
1528
  };
1275
1529
  }
1276
1530
  function summarizeStatuses(statuses) {
@@ -1677,6 +1931,9 @@ function queryAvailabilityProjection(projection, request, runtimeOptions = {}) {
1677
1931
  projection,
1678
1932
  evaluatedAt,
1679
1933
  resourceIds: request.resourceIds,
1934
+ useDurationTimeGrid: runtimeOptions.useDurationTimeGrid,
1935
+ enforceSaleCutoff: runtimeOptions.enforceSaleCutoff,
1936
+ rememberedTimeByProductId: runtimeOptions.rememberedTimeByProductId,
1680
1937
  useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
1681
1938
  allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
1682
1939
  });
@@ -1753,6 +2010,9 @@ function queryAvailabilityProjection(projection, request, runtimeOptions = {}) {
1753
2010
  partySize: normalizedPartySize
1754
2011
  }, {
1755
2012
  evaluatedAt,
2013
+ useDurationTimeGrid: runtimeOptions.useDurationTimeGrid,
2014
+ enforceSaleCutoff: runtimeOptions.enforceSaleCutoff,
2015
+ rememberedTimeByProductId: runtimeOptions.rememberedTimeByProductId,
1756
2016
  useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
1757
2017
  allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
1758
2018
  });
@@ -1777,7 +2037,8 @@ function queryAvailabilityProjection(projection, request, runtimeOptions = {}) {
1777
2037
  candidateRangeCache,
1778
2038
  evaluationContext
1779
2039
  });
1780
- const aggregate = byDate.get(candidate.date) || {
2040
+ const candidateDate = runtimeOptions.useDurationTimeGrid ? candidate.businessDate || candidate.date : candidate.date;
2041
+ const aggregate = byDate.get(candidateDate) || {
1781
2042
  availableCount: 0,
1782
2043
  totalCount: 0,
1783
2044
  maxPartySize: 0,
@@ -1795,8 +2056,24 @@ function queryAvailabilityProjection(projection, request, runtimeOptions = {}) {
1795
2056
  aggregate.maxCapacity += evaluated.maxCapacity;
1796
2057
  pushStatusAggregate(aggregate.statusAggregate, evaluated.status);
1797
2058
  evaluated.reasonCodes.forEach(reasonCode => aggregate.reasonCodeSet.add(reasonCode));
1798
- byDate.set(candidate.date, aggregate);
2059
+ byDate.set(candidateDate, aggregate);
1799
2060
  });
2061
+ if (group.unavailableCurrentTime) {
2062
+ const current = group.unavailableCurrentTime;
2063
+ const aggregate = byDate.get(current.businessDate) || {
2064
+ availableCount: 0,
2065
+ totalCount: 0,
2066
+ maxPartySize: 0,
2067
+ remainingCapacity: 0,
2068
+ maxCapacity: 0,
2069
+ reasonCodeSet: new Set(),
2070
+ statusAggregate: createStatusAggregate()
2071
+ };
2072
+ aggregate.totalCount += 1;
2073
+ pushStatusAggregate(aggregate.statusAggregate, 'unavailable');
2074
+ current.reasonCodes.forEach(reason => aggregate.reasonCodeSet.add(reason));
2075
+ byDate.set(current.businessDate, aggregate);
2076
+ }
1800
2077
  const dates = enumerateDates(dateRange.startDate, dateRange.endDate).map(date => {
1801
2078
  const aggregate = byDate.get(date);
1802
2079
  return {
@@ -1854,10 +2131,20 @@ function queryAvailabilityProjection(projection, request, runtimeOptions = {}) {
1854
2131
  maxPartySize = Math.max(maxPartySize, evaluated.maxPartySize);
1855
2132
  pushStatusAggregate(productStatusAggregate, evaluated.status);
1856
2133
  evaluated.reasonCodes.forEach(reasonCode => productReasonCodeSet.add(reasonCode));
1857
- const dateAggregate = dateStatusMap.get(candidate.date) || createStatusAggregate();
2134
+ const candidateDate = runtimeOptions.useDurationTimeGrid ? candidate.businessDate || candidate.date : candidate.date;
2135
+ const dateAggregate = dateStatusMap.get(candidateDate) || createStatusAggregate();
1858
2136
  pushStatusAggregate(dateAggregate, evaluated.status);
1859
- dateStatusMap.set(candidate.date, dateAggregate);
2137
+ dateStatusMap.set(candidateDate, dateAggregate);
1860
2138
  });
2139
+ if (group.unavailableCurrentTime) {
2140
+ const current = group.unavailableCurrentTime;
2141
+ totalTimeCount += 1;
2142
+ pushStatusAggregate(productStatusAggregate, 'unavailable');
2143
+ current.reasonCodes.forEach(reason => productReasonCodeSet.add(reason));
2144
+ const dateAggregate = dateStatusMap.get(current.businessDate) || createStatusAggregate();
2145
+ pushStatusAggregate(dateAggregate, 'unavailable');
2146
+ dateStatusMap.set(current.businessDate, dateAggregate);
2147
+ }
1861
2148
  const availableDateCount = Array.from(dateStatusMap.values()).filter(aggregate => {
1862
2149
  const status = summarizeStatusAggregate(aggregate);
1863
2150
  return status === 'available' || status === 'limited';
@@ -1926,6 +2213,9 @@ function validateAvailabilitySelection(projection, params, runtimeOptions = {})
1926
2213
  projection,
1927
2214
  evaluatedAt,
1928
2215
  requirementSelections: params.requirementSelections,
2216
+ useDurationTimeGrid: runtimeOptions.useDurationTimeGrid,
2217
+ enforceSaleCutoff: runtimeOptions.enforceSaleCutoff,
2218
+ rememberedTimeByProductId: runtimeOptions.rememberedTimeByProductId,
1929
2219
  useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
1930
2220
  allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
1931
2221
  })
@@ -92,6 +92,9 @@ export interface AvailabilityProduct {
92
92
  raw?: Record<string, any>;
93
93
  }
94
94
  export interface AvailabilityResourceWindow extends AvailabilityAbsoluteRange {
95
+ /** Original business day and opening anchor, before coverage clipping. */
96
+ businessDate?: string;
97
+ openingAnchorAt?: string;
95
98
  source?: string;
96
99
  raw?: Record<string, any>;
97
100
  }
@@ -101,10 +104,15 @@ export interface AvailabilityOperatingHoursSnapshot {
101
104
  scheduleIds: AvailabilityId[];
102
105
  missingScheduleIds: AvailabilityId[];
103
106
  windows: AvailabilityResourceWindow[];
107
+ /** Complete business cycles; lunch gaps remain in windows, not in this envelope. */
108
+ businessPeriods?: AvailabilityBusinessPeriod[];
104
109
  /** Schedule windows omitted only because their date is excluded. POS may use
105
110
  * these to surface an unavailable, manually selectable candidate. */
106
111
  excludedWindows?: AvailabilityResourceWindow[];
107
112
  }
113
+ export interface AvailabilityBusinessPeriod extends AvailabilityAbsoluteRange {
114
+ businessDate: string;
115
+ }
108
116
  export interface AvailabilityResource {
109
117
  id: AvailabilityId;
110
118
  formId?: AvailabilityId;
@@ -212,6 +220,17 @@ export interface ProductTimeRange extends AvailabilityDisplayRange {
212
220
  bookingEndAt: string;
213
221
  scheduleRefs: AvailabilityScheduleRef[];
214
222
  primaryScheduleRef?: AvailabilityScheduleRef;
223
+ /** Business-day label. date/startAt keep the actual calendar date. */
224
+ businessDate?: string;
225
+ }
226
+ export interface UnavailableCurrentTime {
227
+ productId: AvailabilityId;
228
+ startAt: string;
229
+ date: string;
230
+ businessDate: string;
231
+ startTime: string;
232
+ status: 'unavailable';
233
+ reasonCodes: string[];
215
234
  }
216
235
  export interface ProductTimeRangeGroup {
217
236
  productId: AvailabilityId;
@@ -221,6 +240,8 @@ export interface ProductTimeRangeGroup {
221
240
  /** 单日查询对应营业窗口的最终结束时刻,不受资源排班是否为空影响。 */
222
241
  operatingEndAt?: string;
223
242
  ranges: ProductTimeRange[];
243
+ /** A display-only current item when flexible duration has no valid end. Never submit it. */
244
+ unavailableCurrentTime?: UnavailableCurrentTime;
224
245
  }
225
246
  export interface AvailabilityAssignment extends AvailabilityAbsoluteRange {
226
247
  productId: AvailabilityId;
@@ -242,6 +263,19 @@ export interface GetProductTimeRangesRequest {
242
263
  partySize?: number;
243
264
  durationMinutesByProductId?: Record<string, number>;
244
265
  durationStartTimesByProductId?: Record<string, string[]>;
266
+ /** Explicit POS manual interval. Endpoints are absolute datetimes, not business-day HH:mm. */
267
+ requestedRangesByProductId?: Record<string, {
268
+ startAt: string;
269
+ endAt: string;
270
+ }>;
271
+ /** Restore only the exact remembered start; recompute the end from current product/windows. */
272
+ rememberedStartAtByProductId?: Record<string, string>;
273
+ /** Order-scoped v2 memory preserves the complete actual booking interval. */
274
+ rememberedTimeByProductId?: Record<string, AvailabilityAbsoluteRange>;
275
+ /** Required by the POS facade before accepting v2 remembered intervals. */
276
+ orderSessionId?: string;
277
+ /** Edit only: preserve the full actual start plus an explicit durationMinutesByProductId. */
278
+ editingStartAtByProductId?: Record<string, string>;
245
279
  /**
246
280
  * POS 手工输入时间的兼容开关:只为明确请求的 start time 补候选,
247
281
  * 不改变常规候选列表仍按营业时间生成的规则。
@@ -250,6 +284,12 @@ export interface GetProductTimeRangesRequest {
250
284
  }
251
285
  export interface GetProductTimeRangesRuntimeOptions {
252
286
  evaluatedAt?: string;
287
+ /** Enabled by the POS/Kiosk facade only; other consumers retain their existing grid. */
288
+ useDurationTimeGrid?: boolean;
289
+ /** Automatic remembered selection must not use POS opening-minute cutoff exceptions. */
290
+ enforceSaleCutoff?: boolean;
291
+ /** Internal POS capability, validated against the current order session by the facade. */
292
+ rememberedTimeByProductId?: Record<string, AvailabilityAbsoluteRange>;
253
293
  /**
254
294
  * Internal POS capability: fixed-duration candidates start from the stable
255
295
  * context anchor's current minute instead of rounding up to ten minutes, and
@@ -265,6 +305,8 @@ export interface GetProductTimeRangesRuntimeOptions {
265
305
  * disabled.
266
306
  */
267
307
  allowSessionCustomRanges?: boolean;
308
+ /** Internal POS manual capability; automatic/remembered selections must leave this disabled. */
309
+ allowRequestedRanges?: boolean;
268
310
  /**
269
311
  * Internal POS capability: materialize candidates whose schedule date was
270
312
  * explicitly excluded, while availability evaluation keeps them unavailable.
@@ -940,6 +940,34 @@ class RulesModule extends _BaseModule.BaseModule {
940
940
 
941
941
  // 记录已应用优惠券的商品信息
942
942
  const appliedDiscountProducts = new Map();
943
+ const hasPayableOptions = product => {
944
+ return (product.options || []).reduce((total, option) => {
945
+ const unitPrice = Number(option._original_price ?? option._original_add_price ?? option.price ?? option.add_price ?? 0);
946
+ const quantity = Number(option.num ?? option.quantity ?? 1);
947
+ if (!Number.isFinite(unitPrice) || !Number.isFinite(quantity) || quantity <= 0) {
948
+ return total;
949
+ }
950
+ return total.plus(new _decimal.default(unitPrice).mul(quantity));
951
+ }, new _decimal.default(0)).greaterThan(0);
952
+ };
953
+
954
+ // 只排除赠品主项的零可抵扣金额;收费 option 和独立 bundle 保持原有规则。
955
+ const isGiftWithoutDeductibleAmount = (flatItem, discount) => {
956
+ if (flatItem.type !== 'main' || !flatItem.originProduct?.metadata?._giftInfo || Number(flatItem.price || 0) > 0) return false;
957
+ return !discount.config?.deductOptionPrice || !hasPayableOptions(flatItem.product);
958
+ };
959
+
960
+ // 可用性和实际应用共用金额判断;零基础价商品可按策略抵扣收费 option。
961
+ const isDiscountCardPriceAvailable = (flatItem, discount) => {
962
+ const product = flatItem.type === 'main' ? flatItem.product : flatItem.bundleItem;
963
+ if (!(Number(flatItem.price) <= 0 || !flatItem.price) || product.discount_list?.some(item => item.discount?.resource_id === discount.id)) {
964
+ return true;
965
+ }
966
+ if (flatItem.type !== 'main' || Number(flatItem.price) !== 0 || !['discount_card', 'product_discount_card'].includes(discount.tag || discount.type || '') || !discount.config?.deductOptionPrice || (0, _utils.isOrderLevelFixedAmountDiscount)(discount)) {
967
+ return false;
968
+ }
969
+ return hasPayableOptions(product);
970
+ };
943
971
 
944
972
  // 首先遍历所有商品和所有优惠券,确定每个优惠券的适用范围,包括isSelected为false的优惠券
945
973
  // 🔥 使用扁平化后的列表,包含主商品和bundle子商品
@@ -993,7 +1021,7 @@ class RulesModule extends _BaseModule.BaseModule {
993
1021
  }
994
1022
 
995
1023
  // 判断优惠券是否适用于该商品
996
- if (isAvailableProduct && !isItemRewardProductDiscount && isLimitedProduct && timeLimit && isBundleAvailable && discount.config?.isAvailable && (!(0, _entitlementPass.isEntitlementPass)(discount) || (0, _entitlementPass.getRemainingEntitlementUses)(discount, 0, 1) > 0)) {
1024
+ if (isAvailableProduct && !isItemRewardProductDiscount && !isGiftWithoutDeductibleAmount(flatItem, discount) && isLimitedProduct && timeLimit && isBundleAvailable && discount.config?.isAvailable && ((0, _entitlementPass.isFullCoveragePass)(discount) || isDiscountCardPriceAvailable(flatItem, discount)) && (!(0, _entitlementPass.isEntitlementPass)(discount) || (0, _entitlementPass.getRemainingEntitlementUses)(discount, 0, 1) > 0)) {
997
1025
  // 记录此优惠券适用的商品
998
1026
  discountApplicability.get(discount.id)?.push(product.id);
999
1027
  if (flatItem.type === 'main' && (0, _promotionSelection.isPromotionDiscountCard)(discount)) {
@@ -1142,6 +1170,7 @@ class RulesModule extends _BaseModule.BaseModule {
1142
1170
 
1143
1171
  // 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
1144
1172
  const applicableDiscounts = sortedDiscountList.filter(discount => {
1173
+ if (isGiftWithoutDeductibleAmount(flatItem, discount)) return false;
1145
1174
  if (this.discountScope && !this.discountScope(originProduct, discount)) return false;
1146
1175
  if (this.isItemRewardProductDiscount(product)) return false;
1147
1176
  if (isCardBlockedByPromotion(flatItem, discount)) return false;
@@ -1165,8 +1194,8 @@ class RulesModule extends _BaseModule.BaseModule {
1165
1194
  // 全额抵扣卡在主商品价格为 0 时不可用。
1166
1195
  if ((Number(product.price) <= 0 || !product.price) && !product.discount_list?.length && (0, _entitlementPass.isFullCoveragePass)(discount)) return false;
1167
1196
 
1168
- // 折扣卡商品价格为0时不可用
1169
- if ((Number(product.price) <= 0 || !product.price) && !product.discount_list?.find(n => n.discount?.resource_id === discount.id) && !(0, _entitlementPass.isFullCoveragePass)(discount)) return false;
1197
+ // 基础价和策略允许抵扣的 option 都无金额时,折扣卡不可用。
1198
+ if (!(0, _entitlementPass.isFullCoveragePass)(discount) && !isDiscountCardPriceAvailable(flatItem, discount)) return false;
1170
1199
  // good_pass 保持一张实例只使用一次。
1171
1200
  if ((discount.tag || discount.type) === 'good_pass' && usedDiscounts.get(discount.id)) {
1172
1201
  return false;
@@ -14,6 +14,9 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
14
14
  private scheduleListRequestVersion;
15
15
  private scheduleCatalogScope;
16
16
  private otherParams;
17
+ private catalogVersion;
18
+ private destroyed;
19
+ private availabilityRequestVersion;
17
20
  constructor(name?: string, version?: string);
18
21
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
19
22
  /**
@@ -34,12 +37,15 @@ export declare class ScheduleModule extends BaseModule implements Module, Schedu
34
37
  loadAllSchedule(options?: {
35
38
  useCache?: boolean;
36
39
  }): Promise<void>;
40
+ getScheduleCatalogVersion(): number;
41
+ /** Resolve only after the current scope has a successful catalog. */
42
+ ensureScheduleReady(): Promise<void>;
37
43
  private loadScheduleCatalog;
38
44
  setScheduleList(list: ScheduleItem[]): void;
39
45
  private syncScheduleMap;
40
46
  getScheduleList(): ScheduleItem[];
41
47
  isScheduleListLoaded(): boolean;
42
- loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
48
+ loadScheduleAvailableDate({ startDate, endDate, custom_page_id, channel, assertCurrent, }: LoadScheduleAvailableDateParams): Promise<import("../Date/types").ITime[]>;
43
49
  getScheduleListByIds(ids: number[]): ScheduleItem[];
44
50
  setAvailabilityScheduleDateList(list: ScheduleAvailabilityDateItem[]): void;
45
51
  getAvailabilityScheduleDateList(): ScheduleAvailabilityDateItem[];