@pisell/pisellos 2.3.104 → 2.3.106
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 +9 -0
- package/dist/modules/Order/index.js +21 -1
- package/dist/modules/Payment/walletpass.js +20 -21
- package/dist/modules/ResourcePlanner/planner.d.ts +2 -2
- package/dist/modules/ResourcePlanner/planner.js +193 -47
- package/dist/modules/ResourcePlanner/types.d.ts +26 -0
- package/dist/modules/Rules/index.js +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +2 -0
- package/dist/server/utils/small-ticket.js +49 -1
- package/dist/solution/UnifiedBookingSales/index.d.ts +2 -2
- package/dist/solution/UnifiedBookingSales/index.js +121 -40
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/Order/index.js +17 -0
- package/lib/modules/Payment/walletpass.js +14 -11
- package/lib/modules/ResourcePlanner/planner.d.ts +2 -2
- package/lib/modules/ResourcePlanner/planner.js +161 -34
- package/lib/modules/ResourcePlanner/types.d.ts +26 -0
- package/lib/modules/Rules/index.js +1 -1
- package/lib/server/index.d.ts +1 -0
- package/lib/server/index.js +2 -0
- package/lib/server/utils/small-ticket.js +50 -1
- package/lib/solution/UnifiedBookingSales/index.d.ts +2 -2
- package/lib/solution/UnifiedBookingSales/index.js +97 -25
- package/package.json +1 -1
|
@@ -650,17 +650,20 @@ class WalletPassPaymentImpl {
|
|
|
650
650
|
this.paymentModule.logInfo('[WalletPass] 商品列表为空,跳过获取用户识别码列表');
|
|
651
651
|
return [];
|
|
652
652
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
653
|
+
|
|
654
|
+
// const platform = this.paymentModule.getPlatform();
|
|
655
|
+
// if (platform === 'pc' || platform === 'h5') {
|
|
656
|
+
// this.userIdentificationCodes = [];
|
|
657
|
+
// this.emitEvent(WalletPassHooks.OnUserIdentificationCodesUpdated, {
|
|
658
|
+
// userIdentificationCodes: [],
|
|
659
|
+
// } as OnUserIdentificationCodesUpdatedEventData);
|
|
660
|
+
// this.paymentModule.logInfo(
|
|
661
|
+
// '[WalletPass] 用户端平台跳过获取用户识别码列表',
|
|
662
|
+
// { platform },
|
|
663
|
+
// );
|
|
664
|
+
// return [];
|
|
665
|
+
// }
|
|
666
|
+
|
|
664
667
|
if (typeof newParams.payment_order_id === 'string' && newParams.payment_order_id.startsWith('LOCAL_')) {
|
|
665
668
|
newParams.payment_order_id = undefined;
|
|
666
669
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AvailabilityProjection, AvailabilityProjectionInput, AvailabilityQuery, AvailabilityQueryResult, AvailabilitySelectionValidationParams, AvailabilitySelectionValidationResult, GetProductTimeRangesRequest, GetProductTimeRangesRuntimeOptions, ProductTimeRangeGroup } from './types';
|
|
2
2
|
export declare function createAvailabilityProjection(input: AvailabilityProjectionInput): AvailabilityProjection;
|
|
3
3
|
export declare function getProductTimeRanges(projection: AvailabilityProjection, request?: GetProductTimeRangesRequest, runtimeOptions?: GetProductTimeRangesRuntimeOptions): ProductTimeRangeGroup[];
|
|
4
|
-
export declare function queryAvailabilityProjection(projection: AvailabilityProjection, request: AvailabilityQuery): AvailabilityQueryResult;
|
|
5
|
-
export declare function validateAvailabilitySelection(projection: AvailabilityProjection, params: AvailabilitySelectionValidationParams): AvailabilitySelectionValidationResult;
|
|
4
|
+
export declare function queryAvailabilityProjection(projection: AvailabilityProjection, request: AvailabilityQuery, runtimeOptions?: GetProductTimeRangesRuntimeOptions): AvailabilityQueryResult;
|
|
5
|
+
export declare function validateAvailabilitySelection(projection: AvailabilityProjection, params: AvailabilitySelectionValidationParams, runtimeOptions?: GetProductTimeRangesRuntimeOptions): AvailabilitySelectionValidationResult;
|
|
@@ -55,12 +55,18 @@ function resolveRequestedDurationMinutes(product, request) {
|
|
|
55
55
|
const normalized = Number(override);
|
|
56
56
|
return Number.isInteger(normalized) && normalized > 0 ? normalized : configured;
|
|
57
57
|
}
|
|
58
|
-
function resolveRequestedDurationStartTimes(product, request) {
|
|
59
|
-
if (product.kind !== 'duration') return [];
|
|
58
|
+
function resolveRequestedDurationStartTimes(product, request, allowSessionCustomRanges = false) {
|
|
59
|
+
if (product.kind !== 'duration' && !(product.kind === 'session' && allowSessionCustomRanges)) return [];
|
|
60
60
|
const values = request.durationStartTimesByProductId?.[String(product.id)];
|
|
61
61
|
if (!Array.isArray(values)) return [];
|
|
62
62
|
return Array.from(new Set(values.filter(value => typeof value === 'string' && /^([01]\d|2[0-3]):[0-5]\d$/.test(value))));
|
|
63
63
|
}
|
|
64
|
+
function resolveRequestedSessionDurationMinutes(product, request, allowSessionCustomRanges) {
|
|
65
|
+
if (product.kind !== 'session' || !allowSessionCustomRanges) return undefined;
|
|
66
|
+
const override = request.durationMinutesByProductId?.[String(product.id)];
|
|
67
|
+
const normalized = Number(override);
|
|
68
|
+
return Number.isInteger(normalized) && normalized > 0 ? normalized : undefined;
|
|
69
|
+
}
|
|
64
70
|
function toDateTime(value, _timezoneName) {
|
|
65
71
|
try {
|
|
66
72
|
return (0, _localClock.localDateTimeToScalar)((0, _localClock.parseLocalDateTime)(value));
|
|
@@ -160,9 +166,65 @@ function addLeadWindow(base, unit, unitType, _timezoneName) {
|
|
|
160
166
|
if (unitType === 'hours') return (0, _localClock.addLocalHours)(base, unit);
|
|
161
167
|
return (0, _localClock.addLocalMinutes)(base, unit);
|
|
162
168
|
}
|
|
169
|
+
function normalizedWindowContainsRange(windows, candidateRange, timezoneName) {
|
|
170
|
+
return windows.some(window => {
|
|
171
|
+
const normalized = normalizeAbsoluteRange(window, timezoneName);
|
|
172
|
+
return Boolean(normalized && contains(normalized, candidateRange));
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function normalizedWindowsContainDate(windows, date, timezoneName) {
|
|
176
|
+
return windows.some(window => {
|
|
177
|
+
const normalized = normalizeAbsoluteRange(window, timezoneName);
|
|
178
|
+
return Boolean(normalized && formatDate(normalized.start, timezoneName) === date);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
function isRangeFromExcludedWindows(params) {
|
|
182
|
+
const candidateDate = formatDate(params.candidateRange.start, params.timezoneName);
|
|
183
|
+
const hasNormalWindowOnDate = normalizedWindowsContainDate(params.normalWindows, candidateDate, params.timezoneName);
|
|
184
|
+
const hasExcludedWindowOnDate = normalizedWindowsContainDate(params.excludedWindows, candidateDate, params.timezoneName);
|
|
185
|
+
if (!hasNormalWindowOnDate && hasExcludedWindowOnDate) return true;
|
|
186
|
+
return !normalizedWindowContainsRange(params.normalWindows, params.candidateRange, params.timezoneName) && normalizedWindowContainsRange(params.excludedWindows, params.candidateRange, params.timezoneName);
|
|
187
|
+
}
|
|
188
|
+
function isCandidateFromExcludedScheduleDate(params) {
|
|
189
|
+
const {
|
|
190
|
+
projection,
|
|
191
|
+
product,
|
|
192
|
+
candidate,
|
|
193
|
+
candidateRange
|
|
194
|
+
} = params;
|
|
195
|
+
const operatingHours = projection.meta.defaults.operatingHours;
|
|
196
|
+
if (isRangeFromExcludedWindows({
|
|
197
|
+
normalWindows: operatingHours.windows,
|
|
198
|
+
excludedWindows: operatingHours.excludedWindows || [],
|
|
199
|
+
candidateRange,
|
|
200
|
+
timezoneName: projection.meta.timezone
|
|
201
|
+
})) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
if (product.kind !== 'session' && product.kind !== 'venue_slot') {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
if (candidate.source !== 'session_schedule') {
|
|
208
|
+
const hasNormalRule = (product.sessionRules || []).some(rule => matchesScheduleRuleDate(rule, candidate.date, projection.meta.timezone));
|
|
209
|
+
const hasExcludedOverrideRule = (product.sessionRules || []).some(rule => !matchesScheduleRuleDate(rule, candidate.date, projection.meta.timezone) && matchesScheduleRuleDate(rule, candidate.date, projection.meta.timezone, true));
|
|
210
|
+
return !hasNormalRule && hasExcludedOverrideRule;
|
|
211
|
+
}
|
|
212
|
+
const candidateDateRange = {
|
|
213
|
+
startDate: candidate.date,
|
|
214
|
+
endDate: candidate.date
|
|
215
|
+
};
|
|
216
|
+
const candidateIdentity = getProductTimeRangeIdentity(candidate);
|
|
217
|
+
const normalRanges = getSessionRangesForProduct(projection, product, candidateDateRange);
|
|
218
|
+
if (normalRanges.some(range => getProductTimeRangeIdentity(range) === candidateIdentity)) {
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
return getSessionRangesForProduct(projection, product, candidateDateRange, true).some(range => getProductTimeRangeIdentity(range) === candidateIdentity);
|
|
222
|
+
}
|
|
163
223
|
function evaluateCandidateTimeGate(params) {
|
|
164
224
|
const {
|
|
225
|
+
projection,
|
|
165
226
|
product,
|
|
227
|
+
candidate,
|
|
166
228
|
candidateRange,
|
|
167
229
|
evaluationContext,
|
|
168
230
|
timezoneName
|
|
@@ -175,6 +237,18 @@ function evaluateCandidateTimeGate(params) {
|
|
|
175
237
|
conflictCode: 'past'
|
|
176
238
|
};
|
|
177
239
|
}
|
|
240
|
+
if (evaluationContext.allowExcludedScheduleDateOverride && isCandidateFromExcludedScheduleDate({
|
|
241
|
+
projection,
|
|
242
|
+
product,
|
|
243
|
+
candidate,
|
|
244
|
+
candidateRange
|
|
245
|
+
})) {
|
|
246
|
+
return {
|
|
247
|
+
status: 'unavailable',
|
|
248
|
+
reasonCodes: ['schedule_excluded_date'],
|
|
249
|
+
conflictCode: 'schedule_excluded_date'
|
|
250
|
+
};
|
|
251
|
+
}
|
|
178
252
|
const policy = product.cutOffPolicy;
|
|
179
253
|
if (!policy) return null;
|
|
180
254
|
if (resolveCutOffPolicyIssue(policy)) {
|
|
@@ -207,7 +281,13 @@ function evaluateCandidateTimeGate(params) {
|
|
|
207
281
|
};
|
|
208
282
|
}
|
|
209
283
|
if (policy.type === 'before_start') {
|
|
210
|
-
|
|
284
|
+
// Flexible-duration candidates and POS fixed-duration anchors start at
|
|
285
|
+
// minute precision. Keep that current minute selectable instead of treating
|
|
286
|
+
// the freshly generated candidate as already started because the query
|
|
287
|
+
// clock still contains seconds.
|
|
288
|
+
const usesMinutePrecision = product.isFlexibleDuration || evaluationContext.useExactDurationCandidateMinute && product.kind === 'duration';
|
|
289
|
+
const hasNotReachedStart = usesMinutePrecision ? floorToMinute(now) <= candidateRange.start : now < candidateRange.start;
|
|
290
|
+
if (hasNotReachedStart) return null;
|
|
211
291
|
return {
|
|
212
292
|
status: 'unavailable',
|
|
213
293
|
reasonCodes: ['booking_cutoff_before_start'],
|
|
@@ -314,8 +394,8 @@ function normalizeCoverage(input) {
|
|
|
314
394
|
}
|
|
315
395
|
};
|
|
316
396
|
}
|
|
317
|
-
function normalizeResourceWindow(resource, coverage, timezoneName) {
|
|
318
|
-
return mergeRanges((resource.windows || []).map(window => normalizeAbsoluteRange(window, timezoneName)).filter(window => Boolean(window)).map(window => clipRange(window, coverage)).filter(window => Boolean(window)));
|
|
397
|
+
function normalizeResourceWindow(resource, coverage, timezoneName, includeExcludedWindows = false) {
|
|
398
|
+
return mergeRanges([...(resource.windows || []), ...(includeExcludedWindows ? resource.excludedWindows || [] : [])].map(window => normalizeAbsoluteRange(window, timezoneName)).filter(window => Boolean(window)).map(window => clipRange(window, coverage)).filter(window => Boolean(window)));
|
|
319
399
|
}
|
|
320
400
|
function normalizeOccupancy(occupancy, coverage, timezoneName, fixedOffsetMinutes) {
|
|
321
401
|
const normalized = normalizeAbsoluteRange(occupancy, timezoneName);
|
|
@@ -379,6 +459,9 @@ function normalizeResources(resources) {
|
|
|
379
459
|
capacity: Math.max(1, Number(resource.capacity || 1) || 1),
|
|
380
460
|
windows: (resource.windows || []).map(window => ({
|
|
381
461
|
...window
|
|
462
|
+
})),
|
|
463
|
+
excludedWindows: (resource.excludedWindows || []).map(window => ({
|
|
464
|
+
...window
|
|
382
465
|
}))
|
|
383
466
|
}));
|
|
384
467
|
}
|
|
@@ -398,15 +481,20 @@ function normalizeOperatingHours(params) {
|
|
|
398
481
|
startAt: formatDateTime(range.start, params.timezoneName, params.fixedOffsetMinutes),
|
|
399
482
|
endAt: formatDateTime(range.end, params.timezoneName, params.fixedOffsetMinutes)
|
|
400
483
|
}));
|
|
401
|
-
const
|
|
484
|
+
const normalizeWindows = source => mergeRanges(source.map(window => normalizeAbsoluteRange(window, params.timezoneName)).filter(window => Boolean(window)).map(window => clipRange(window, params.coverage)).filter(window => Boolean(window))).map(range => ({
|
|
402
485
|
startAt: formatDateTime(range.start, params.timezoneName, params.fixedOffsetMinutes),
|
|
403
486
|
endAt: formatDateTime(range.end, params.timezoneName, params.fixedOffsetMinutes)
|
|
404
487
|
}));
|
|
488
|
+
const windows = normalizeWindows(sourceWindows);
|
|
489
|
+
const excludedWindows = normalizeWindows(params.input?.excludedWindows || []);
|
|
405
490
|
return {
|
|
406
491
|
source: params.input?.source || params.fallbackSource,
|
|
407
492
|
scheduleIds: uniqById(params.input?.scheduleIds || []),
|
|
408
493
|
missingScheduleIds: uniqById(params.input?.missingScheduleIds || []),
|
|
409
|
-
windows
|
|
494
|
+
windows,
|
|
495
|
+
...(excludedWindows.length > 0 ? {
|
|
496
|
+
excludedWindows
|
|
497
|
+
} : {})
|
|
410
498
|
};
|
|
411
499
|
}
|
|
412
500
|
function matchesRequirementGroup(requirementGroup, resource, product, partySize = 1) {
|
|
@@ -688,19 +776,19 @@ function resolveProjectionDateRange(projection, requestDateRange) {
|
|
|
688
776
|
endDate
|
|
689
777
|
};
|
|
690
778
|
}
|
|
691
|
-
function buildOperatingRanges(projection, dateRange) {
|
|
779
|
+
function buildOperatingRanges(projection, dateRange, includeExcludedWindows = false) {
|
|
692
780
|
const coverage = {
|
|
693
781
|
start: toDateStart(dateRange.startDate, projection.meta.timezone),
|
|
694
782
|
end: toDateEnd(nextDate(dateRange.endDate), projection.meta.timezone)
|
|
695
783
|
};
|
|
696
|
-
return mergeRanges(projection.meta.defaults.operatingHours.windows.map(window => normalizeAbsoluteRange(window, projection.meta.timezone)).filter(window => Boolean(window)).map(window => clipRange(window, coverage)).filter(window => Boolean(window)));
|
|
784
|
+
return mergeRanges([...projection.meta.defaults.operatingHours.windows, ...(includeExcludedWindows ? projection.meta.defaults.operatingHours.excludedWindows || [] : [])].map(window => normalizeAbsoluteRange(window, projection.meta.timezone)).filter(window => Boolean(window)).map(window => clipRange(window, coverage)).filter(window => Boolean(window)));
|
|
697
785
|
}
|
|
698
|
-
function buildResourceWindowIndex(projection) {
|
|
786
|
+
function buildResourceWindowIndex(projection, includeExcludedWindows = false) {
|
|
699
787
|
const coverage = {
|
|
700
788
|
start: toDateTime(projection.meta.coverage.startAt, projection.meta.timezone),
|
|
701
789
|
end: toDateTime(projection.meta.coverage.endAt, projection.meta.timezone)
|
|
702
790
|
};
|
|
703
|
-
return new Map(projection.resources.map(resource => [String(resource.id), normalizeResourceWindow(resource, coverage, projection.meta.timezone)]));
|
|
791
|
+
return new Map(projection.resources.map(resource => [String(resource.id), normalizeResourceWindow(resource, coverage, projection.meta.timezone, includeExcludedWindows)]));
|
|
704
792
|
}
|
|
705
793
|
function buildGroupWorkingRanges(params) {
|
|
706
794
|
const {
|
|
@@ -717,7 +805,7 @@ function buildGroupWorkingRanges(params) {
|
|
|
717
805
|
};
|
|
718
806
|
const filteredResourceIdSet = resourceIds?.length ? new Set(resourceIds.map(String)) : null;
|
|
719
807
|
const resourceWindows = projection.resources.filter(resource => matchesRequirementGroup(requirementGroup, resource, params.product, partySize)).filter(resource => !filteredResourceIdSet || filteredResourceIdSet.has(String(resource.id))).map(resource => {
|
|
720
|
-
const windows = params.resourceWindowIndex?.get(String(resource.id)) || normalizeResourceWindow(resource, coverage, projection.meta.timezone);
|
|
808
|
+
const windows = params.resourceWindowIndex?.get(String(resource.id)) || normalizeResourceWindow(resource, coverage, projection.meta.timezone, params.includeExcludedWindows === true);
|
|
721
809
|
return windows.map(window => clipRange(window, coverage)).filter(window => Boolean(window));
|
|
722
810
|
});
|
|
723
811
|
const requiredConcurrentResources = Math.max(requirementGroup.required === false ? 0 : 1, Number(requirementGroup.min ?? (requirementGroup.required === false ? 0 : 1)) || 0);
|
|
@@ -748,12 +836,12 @@ function buildGroupWorkingRanges(params) {
|
|
|
748
836
|
}
|
|
749
837
|
return mergeRanges(satisfiedRanges);
|
|
750
838
|
}
|
|
751
|
-
function materializeScheduleRules(rules, dateRange, timezoneName, fixedOffsetMinutes) {
|
|
839
|
+
function materializeScheduleRules(rules, dateRange, timezoneName, fixedOffsetMinutes, allowExcludedScheduleDates = false) {
|
|
752
840
|
const dates = enumerateDates(dateRange.startDate, dateRange.endDate);
|
|
753
841
|
const seen = new Map();
|
|
754
842
|
rules.forEach(rule => {
|
|
755
843
|
dates.forEach(date => {
|
|
756
|
-
if (!matchesScheduleRuleDate(rule, date, timezoneName)) return;
|
|
844
|
+
if (!matchesScheduleRuleDate(rule, date, timezoneName, allowExcludedScheduleDates)) return;
|
|
757
845
|
const start = toDateTimeInDate(date, rule.startTime, timezoneName);
|
|
758
846
|
let end = toDateTimeInDate(date, rule.endTime, timezoneName);
|
|
759
847
|
if (end <= start) end = toDateTimeInDate(nextDate(date, timezoneName), rule.endTime, timezoneName);
|
|
@@ -785,9 +873,9 @@ function materializeScheduleRules(rules, dateRange, timezoneName, fixedOffsetMin
|
|
|
785
873
|
});
|
|
786
874
|
return Array.from(seen.values());
|
|
787
875
|
}
|
|
788
|
-
function matchesScheduleRuleDate(rule, date, _timezoneName) {
|
|
876
|
+
function matchesScheduleRuleDate(rule, date, _timezoneName, allowExcludedScheduleDate = false) {
|
|
789
877
|
if (rule.includeDates?.includes(date)) return true;
|
|
790
|
-
if (rule.excludeDates?.includes(date)) return false;
|
|
878
|
+
if (!allowExcludedScheduleDate && rule.excludeDates?.includes(date)) return false;
|
|
791
879
|
if (rule.startDate && date < rule.startDate) return false;
|
|
792
880
|
if (rule.endDate && date > rule.endDate) return false;
|
|
793
881
|
if (rule.mode === 'designation') {
|
|
@@ -831,7 +919,7 @@ function buildGroupResourceIndex(params) {
|
|
|
831
919
|
});
|
|
832
920
|
return index;
|
|
833
921
|
}
|
|
834
|
-
function getSessionRangesForProduct(projection, product, dateRange) {
|
|
922
|
+
function getSessionRangesForProduct(projection, product, dateRange, allowExcludedScheduleDates = false) {
|
|
835
923
|
const fixedOffsetMinutes = (0, _localClock.extractFixedOffsetMinutes)(projection.meta.now) ?? (0, _localClock.captureRuntimeOffsetMinutes)();
|
|
836
924
|
const ranges = (product.sessionRanges || []).map(range => {
|
|
837
925
|
const normalized = normalizeAbsoluteRange(range, projection.meta.timezone);
|
|
@@ -856,7 +944,7 @@ function getSessionRangesForProduct(projection, product, dateRange) {
|
|
|
856
944
|
primaryScheduleRef: range.scheduleRefs?.[0]
|
|
857
945
|
};
|
|
858
946
|
}).filter(Boolean);
|
|
859
|
-
const ruleRanges = materializeScheduleRules(product.sessionRules || [], dateRange, projection.meta.timezone, fixedOffsetMinutes);
|
|
947
|
+
const ruleRanges = materializeScheduleRules(product.sessionRules || [], dateRange, projection.meta.timezone, fixedOffsetMinutes, allowExcludedScheduleDates);
|
|
860
948
|
return dedupeProductRanges([...ranges, ...ruleRanges.map(range => ({
|
|
861
949
|
...range,
|
|
862
950
|
key: `${String(product.id)}:${range.startAt}:${range.endAt}`,
|
|
@@ -906,7 +994,8 @@ function getProductTimeRanges(projection, request = {}, runtimeOptions = {}) {
|
|
|
906
994
|
const dateRange = resolveProjectionDateRange(projection, request.dateRange);
|
|
907
995
|
const slotStepMinutes = projection.meta.defaults.slotStepMinutes;
|
|
908
996
|
const fixedOffsetMinutes = (0, _localClock.extractFixedOffsetMinutes)(projection.meta.now) ?? (0, _localClock.captureRuntimeOffsetMinutes)();
|
|
909
|
-
const
|
|
997
|
+
const allowExcludedScheduleDateOverride = runtimeOptions.allowExcludedScheduleDateOverride === true;
|
|
998
|
+
const resourceWindowIndex = buildResourceWindowIndex(projection, allowExcludedScheduleDateOverride);
|
|
910
999
|
const filteredProductIdSet = request.productIds?.length ? new Set(request.productIds.map(String)) : null;
|
|
911
1000
|
return projection.products.filter(product => !filteredProductIdSet || filteredProductIdSet.has(String(product.id))).map(product => {
|
|
912
1001
|
if (product.kind === 'normal') {
|
|
@@ -919,16 +1008,28 @@ function getProductTimeRanges(projection, request = {}, runtimeOptions = {}) {
|
|
|
919
1008
|
};
|
|
920
1009
|
}
|
|
921
1010
|
if (product.kind === 'session' || product.kind === 'venue_slot') {
|
|
1011
|
+
const fixedRanges = getSessionRangesForProduct(projection, product, dateRange, allowExcludedScheduleDateOverride);
|
|
1012
|
+
const customRanges = [];
|
|
1013
|
+
const customDurationMinutes = resolveRequestedSessionDurationMinutes(product, request, runtimeOptions.allowSessionCustomRanges === true);
|
|
1014
|
+
const requestedStartTimes = resolveRequestedDurationStartTimes(product, request, runtimeOptions.allowSessionCustomRanges === true);
|
|
1015
|
+
if (product.kind === 'session' && customDurationMinutes && dateRange.startDate === dateRange.endDate) {
|
|
1016
|
+
requestedStartTimes.forEach(startTime => {
|
|
1017
|
+
const start = toDateTimeInDate(dateRange.startDate, startTime, projection.meta.timezone);
|
|
1018
|
+
if (!Number.isFinite(start)) return;
|
|
1019
|
+
customRanges.push(createDurationTimeRange(product, start, customDurationMinutes, projection, fixedOffsetMinutes));
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
922
1022
|
return {
|
|
923
1023
|
productId: product.id,
|
|
924
1024
|
title: product.title,
|
|
925
1025
|
kind: product.kind,
|
|
926
1026
|
slotStepMinutes,
|
|
927
|
-
ranges:
|
|
1027
|
+
ranges: dedupeProductRanges([...fixedRanges, ...customRanges])
|
|
928
1028
|
};
|
|
929
1029
|
}
|
|
930
1030
|
const requiredGroups = (product.requirementGroups || []).filter(group => group.required !== false);
|
|
931
|
-
const operatingRanges = buildOperatingRanges(projection, dateRange);
|
|
1031
|
+
const operatingRanges = buildOperatingRanges(projection, dateRange, allowExcludedScheduleDateOverride);
|
|
1032
|
+
const operatingEndAt = dateRange.startDate === dateRange.endDate && operatingRanges.length > 0 ? formatDateTime(Math.max(...operatingRanges.map(range => range.end)), projection.meta.timezone, fixedOffsetMinutes) : undefined;
|
|
932
1033
|
const resourceRanges = requiredGroups.length ? requiredGroups.map(group => buildGroupWorkingRanges({
|
|
933
1034
|
projection,
|
|
934
1035
|
product,
|
|
@@ -936,7 +1037,8 @@ function getProductTimeRanges(projection, request = {}, runtimeOptions = {}) {
|
|
|
936
1037
|
dateRange,
|
|
937
1038
|
resourceIds: request.resourceIds,
|
|
938
1039
|
partySize: normalizedPartySize,
|
|
939
|
-
resourceWindowIndex
|
|
1040
|
+
resourceWindowIndex,
|
|
1041
|
+
includeExcludedWindows: allowExcludedScheduleDateOverride
|
|
940
1042
|
})).reduce((current, ranges) => current === null ? ranges : intersectRangeLists(current, ranges), null) || [] : null;
|
|
941
1043
|
const baseRanges = resourceRanges === null ? operatingRanges : intersectRangeLists(resourceRanges, operatingRanges);
|
|
942
1044
|
const durationMinutes = resolveRequestedDurationMinutes(product, request);
|
|
@@ -950,7 +1052,8 @@ function getProductTimeRanges(projection, request = {}, runtimeOptions = {}) {
|
|
|
950
1052
|
}
|
|
951
1053
|
return floorToMinute(evaluatedAt);
|
|
952
1054
|
})();
|
|
953
|
-
const
|
|
1055
|
+
const durationCandidateAnchor = toDateTime(projection.meta.durationCandidateAnchorAt, projection.meta.timezone);
|
|
1056
|
+
const durationAnchor = runtimeOptions.useExactDurationCandidateMinute ? floorToMinute(durationCandidateAnchor) : ceilToTenMinutes(durationCandidateAnchor, projection.meta.timezone);
|
|
954
1057
|
const requestedStartTimes = resolveRequestedDurationStartTimes(product, request);
|
|
955
1058
|
const ranges = [];
|
|
956
1059
|
baseRanges.forEach(range => {
|
|
@@ -995,6 +1098,9 @@ function getProductTimeRanges(projection, request = {}, runtimeOptions = {}) {
|
|
|
995
1098
|
title: product.title,
|
|
996
1099
|
kind: product.kind,
|
|
997
1100
|
slotStepMinutes,
|
|
1101
|
+
...(operatingEndAt ? {
|
|
1102
|
+
operatingEndAt
|
|
1103
|
+
} : {}),
|
|
998
1104
|
ranges: dedupeProductRanges(ranges)
|
|
999
1105
|
};
|
|
1000
1106
|
});
|
|
@@ -1152,7 +1258,9 @@ function buildEvaluationContext(params) {
|
|
|
1152
1258
|
evaluatedAt,
|
|
1153
1259
|
evaluatedAtMs: evaluatedAt,
|
|
1154
1260
|
resourceIdSet: params.resourceIds?.length ? new Set(params.resourceIds.map(String)) : null,
|
|
1155
|
-
selectionsByGroupKey
|
|
1261
|
+
selectionsByGroupKey,
|
|
1262
|
+
useExactDurationCandidateMinute: params.useExactDurationCandidateMinute === true,
|
|
1263
|
+
allowExcludedScheduleDateOverride: params.allowExcludedScheduleDateOverride === true
|
|
1156
1264
|
};
|
|
1157
1265
|
}
|
|
1158
1266
|
function summarizeStatuses(statuses) {
|
|
@@ -1302,7 +1410,8 @@ function evaluateCandidateSummary(projection, candidate, request) {
|
|
|
1302
1410
|
const evaluationContext = request.evaluationContext || buildEvaluationContext({
|
|
1303
1411
|
projection,
|
|
1304
1412
|
evaluatedAt: request.evaluatedAt,
|
|
1305
|
-
resourceIds: request.resourceIds
|
|
1413
|
+
resourceIds: request.resourceIds,
|
|
1414
|
+
allowExcludedScheduleDateOverride: request.allowExcludedScheduleDateOverride
|
|
1306
1415
|
});
|
|
1307
1416
|
const requestedPartySize = normalizePartySize(request.partySize);
|
|
1308
1417
|
const requiredGroups = (product.requirementGroups || []).filter(group => group.required !== false).map(requirementGroup => evaluateRequirementGroupSummary({
|
|
@@ -1316,7 +1425,9 @@ function evaluateCandidateSummary(projection, candidate, request) {
|
|
|
1316
1425
|
groupResourceIndex: request.groupResourceIndex
|
|
1317
1426
|
}));
|
|
1318
1427
|
const gate = evaluateCandidateTimeGate({
|
|
1428
|
+
projection,
|
|
1319
1429
|
product,
|
|
1430
|
+
candidate,
|
|
1320
1431
|
candidateRange,
|
|
1321
1432
|
evaluationContext,
|
|
1322
1433
|
timezoneName: projection.meta.timezone
|
|
@@ -1358,7 +1469,8 @@ function evaluateCandidate(projection, candidate, request) {
|
|
|
1358
1469
|
projection,
|
|
1359
1470
|
evaluatedAt: request.evaluatedAt,
|
|
1360
1471
|
resourceIds: request.resourceIds,
|
|
1361
|
-
requirementSelections: request.requirementSelections
|
|
1472
|
+
requirementSelections: request.requirementSelections,
|
|
1473
|
+
allowExcludedScheduleDateOverride: request.allowExcludedScheduleDateOverride
|
|
1362
1474
|
});
|
|
1363
1475
|
const requestedPartySize = normalizePartySize(request.partySize);
|
|
1364
1476
|
const partySize = requestedPartySize ?? 1;
|
|
@@ -1371,6 +1483,12 @@ function evaluateCandidate(projection, candidate, request) {
|
|
|
1371
1483
|
const matchedResources = (request.groupResourceIndex?.get([String(product.id), requirementGroup.id].join(':')) || projection.resources.filter(resource => matchesRequirementGroup(requirementGroup, resource, product, partySize)).filter(resource => !evaluationContext.resourceIdSet || evaluationContext.resourceIdSet.has(String(resource.id)))).filter(resource => !selection || selection.resourceIds.some(resourceId => sameId(resourceId, resource.id)));
|
|
1372
1484
|
const options = matchedResources.map(resource => {
|
|
1373
1485
|
const matchedCell = aggregateMatchedCells(product.id, requirementGroup.id, resource.id, candidateRange, request.cellIndex?.get([String(product.id), requirementGroup.id, String(resource.id)].join(':')) || []);
|
|
1486
|
+
const isExcludedScheduleDate = evaluationContext.allowExcludedScheduleDateOverride && isRangeFromExcludedWindows({
|
|
1487
|
+
normalWindows: resource.windows || [],
|
|
1488
|
+
excludedWindows: resource.excludedWindows || [],
|
|
1489
|
+
candidateRange,
|
|
1490
|
+
timezoneName: projection.meta.timezone
|
|
1491
|
+
});
|
|
1374
1492
|
if (!matchedCell) {
|
|
1375
1493
|
const isPast = candidateRange.endMs <= evaluationContext.evaluatedAtMs;
|
|
1376
1494
|
return {
|
|
@@ -1381,7 +1499,7 @@ function evaluateCandidate(projection, candidate, request) {
|
|
|
1381
1499
|
resourceType: resource.resourceType,
|
|
1382
1500
|
status: isPast ? 'past' : 'unavailable',
|
|
1383
1501
|
maxPartySize: 0,
|
|
1384
|
-
reasonCodes: isPast ? ['past'] : ['outside_resource_window']
|
|
1502
|
+
reasonCodes: isPast ? ['past'] : [...(isExcludedScheduleDate ? ['schedule_excluded_date'] : []), 'outside_resource_window']
|
|
1385
1503
|
};
|
|
1386
1504
|
}
|
|
1387
1505
|
const remainingCapacity = matchedCell.remainingCapacity;
|
|
@@ -1389,6 +1507,7 @@ function evaluateCandidate(projection, candidate, request) {
|
|
|
1389
1507
|
const isPast = candidateRange.endMs <= evaluationContext.evaluatedAtMs;
|
|
1390
1508
|
const maxPartySize = isPast ? 0 : Math.max(0, remainingCapacity || 0);
|
|
1391
1509
|
const requiredCapacity = resolveRequiredCapacity(requirementGroup, product, requestedPartySize);
|
|
1510
|
+
const reasonCodes = Array.from(new Set([...matchedCell.reasonCodes, ...(isExcludedScheduleDate ? ['schedule_excluded_date'] : [])]));
|
|
1392
1511
|
const status = (() => {
|
|
1393
1512
|
if (isPast) return 'past';
|
|
1394
1513
|
if (matchedCell.status === 'unavailable') return 'unavailable';
|
|
@@ -1406,7 +1525,7 @@ function evaluateCandidate(projection, candidate, request) {
|
|
|
1406
1525
|
remainingCapacity,
|
|
1407
1526
|
maxCapacity,
|
|
1408
1527
|
maxPartySize,
|
|
1409
|
-
reasonCodes: isPast ? Array.from(new Set([...
|
|
1528
|
+
reasonCodes: isPast ? Array.from(new Set([...reasonCodes, 'past'])) : reasonCodes,
|
|
1410
1529
|
matchedCell
|
|
1411
1530
|
};
|
|
1412
1531
|
});
|
|
@@ -1446,7 +1565,9 @@ function evaluateCandidate(projection, candidate, request) {
|
|
|
1446
1565
|
const requiredGroups = requirementGroups.filter(group => group.required);
|
|
1447
1566
|
const requiredStatuses = requiredGroups.map(group => group.status);
|
|
1448
1567
|
const gate = evaluateCandidateTimeGate({
|
|
1568
|
+
projection,
|
|
1449
1569
|
product,
|
|
1570
|
+
candidate,
|
|
1450
1571
|
candidateRange,
|
|
1451
1572
|
evaluationContext,
|
|
1452
1573
|
timezoneName: projection.meta.timezone
|
|
@@ -1522,7 +1643,7 @@ function assertRangesWithinProjection(projection, ranges) {
|
|
|
1522
1643
|
}
|
|
1523
1644
|
});
|
|
1524
1645
|
}
|
|
1525
|
-
function queryAvailabilityProjection(projection, request) {
|
|
1646
|
+
function queryAvailabilityProjection(projection, request, runtimeOptions = {}) {
|
|
1526
1647
|
const normalizedPartySize = normalizePartySize(request.partySize);
|
|
1527
1648
|
const evaluatedAt = formatDateTime((0, _localClock.localDateToScalar)(new Date()), projection.meta.timezone, (0, _localClock.extractFixedOffsetMinutes)(projection.meta.now) ?? (0, _localClock.captureRuntimeOffsetMinutes)());
|
|
1528
1649
|
if (request.target === 'time') {
|
|
@@ -1545,7 +1666,9 @@ function queryAvailabilityProjection(projection, request) {
|
|
|
1545
1666
|
const evaluationContext = buildEvaluationContext({
|
|
1546
1667
|
projection,
|
|
1547
1668
|
evaluatedAt,
|
|
1548
|
-
resourceIds: request.resourceIds
|
|
1669
|
+
resourceIds: request.resourceIds,
|
|
1670
|
+
useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
|
|
1671
|
+
allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
|
|
1549
1672
|
});
|
|
1550
1673
|
if (request.target === 'time') {
|
|
1551
1674
|
const candidates = dedupeProductRanges(request.candidates);
|
|
@@ -1619,7 +1742,9 @@ function queryAvailabilityProjection(projection, request) {
|
|
|
1619
1742
|
resourceIds: request.resourceIds,
|
|
1620
1743
|
partySize: normalizedPartySize
|
|
1621
1744
|
}, {
|
|
1622
|
-
evaluatedAt
|
|
1745
|
+
evaluatedAt,
|
|
1746
|
+
useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
|
|
1747
|
+
allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
|
|
1623
1748
|
});
|
|
1624
1749
|
const candidateGroupMap = new Map(candidateGroups.map(group => [String(group.productId), group]));
|
|
1625
1750
|
if (request.target === 'date') {
|
|
@@ -1769,7 +1894,7 @@ function summarizeProductStatus(statuses) {
|
|
|
1769
1894
|
if (statuses.every(status => status === 'past')) return 'past';
|
|
1770
1895
|
return 'unavailable';
|
|
1771
1896
|
}
|
|
1772
|
-
function validateAvailabilitySelection(projection, params) {
|
|
1897
|
+
function validateAvailabilitySelection(projection, params, runtimeOptions = {}) {
|
|
1773
1898
|
const normalizedPartySize = normalizePartySize(params.partySize);
|
|
1774
1899
|
const normalizedBookingCount = normalizeBookingCount(params.bookingCount);
|
|
1775
1900
|
assertRangesWithinProjection(projection, [params.candidate]);
|
|
@@ -1790,14 +1915,16 @@ function validateAvailabilitySelection(projection, params) {
|
|
|
1790
1915
|
evaluationContext: buildEvaluationContext({
|
|
1791
1916
|
projection,
|
|
1792
1917
|
evaluatedAt,
|
|
1793
|
-
requirementSelections: params.requirementSelections
|
|
1918
|
+
requirementSelections: params.requirementSelections,
|
|
1919
|
+
useExactDurationCandidateMinute: runtimeOptions.useExactDurationCandidateMinute,
|
|
1920
|
+
allowExcludedScheduleDateOverride: runtimeOptions.allowExcludedScheduleDateOverride
|
|
1794
1921
|
})
|
|
1795
1922
|
});
|
|
1796
1923
|
const conflicts = [];
|
|
1797
1924
|
if (evaluated.gate) {
|
|
1798
1925
|
conflicts.push({
|
|
1799
1926
|
code: evaluated.gate.conflictCode,
|
|
1800
|
-
message: evaluated.gate.
|
|
1927
|
+
message: evaluated.gate.conflictCode === 'past' ? '候选时间已过期' : evaluated.gate.conflictCode === 'schedule_excluded_date' ? '候选日期已被日程排除' : '候选时间不满足预订时间门禁',
|
|
1801
1928
|
reasonCodes: evaluated.gate.reasonCodes,
|
|
1802
1929
|
productId: params.candidate.productId,
|
|
1803
1930
|
candidateKey: params.candidate.key
|
|
@@ -101,6 +101,9 @@ export interface AvailabilityOperatingHoursSnapshot {
|
|
|
101
101
|
scheduleIds: AvailabilityId[];
|
|
102
102
|
missingScheduleIds: AvailabilityId[];
|
|
103
103
|
windows: AvailabilityResourceWindow[];
|
|
104
|
+
/** Schedule windows omitted only because their date is excluded. POS may use
|
|
105
|
+
* these to surface an unavailable, manually selectable candidate. */
|
|
106
|
+
excludedWindows?: AvailabilityResourceWindow[];
|
|
104
107
|
}
|
|
105
108
|
export interface AvailabilityResource {
|
|
106
109
|
id: AvailabilityId;
|
|
@@ -110,6 +113,8 @@ export interface AvailabilityResource {
|
|
|
110
113
|
resourceType: AvailabilityResourceType;
|
|
111
114
|
capacity: number;
|
|
112
115
|
windows: AvailabilityResourceWindow[];
|
|
116
|
+
/** Resource work windows omitted only by an excluded schedule date. */
|
|
117
|
+
excludedWindows?: AvailabilityResourceWindow[];
|
|
113
118
|
raw?: Record<string, any>;
|
|
114
119
|
}
|
|
115
120
|
export interface AvailabilityOccupancy extends AvailabilityAbsoluteRange {
|
|
@@ -213,6 +218,8 @@ export interface ProductTimeRangeGroup {
|
|
|
213
218
|
title?: string;
|
|
214
219
|
kind: AvailabilityProductKind;
|
|
215
220
|
slotStepMinutes?: number;
|
|
221
|
+
/** 单日查询对应营业窗口的最终结束时刻,不受资源排班是否为空影响。 */
|
|
222
|
+
operatingEndAt?: string;
|
|
216
223
|
ranges: ProductTimeRange[];
|
|
217
224
|
}
|
|
218
225
|
export interface AvailabilityAssignment extends AvailabilityAbsoluteRange {
|
|
@@ -243,6 +250,25 @@ export interface GetProductTimeRangesRequest {
|
|
|
243
250
|
}
|
|
244
251
|
export interface GetProductTimeRangesRuntimeOptions {
|
|
245
252
|
evaluatedAt?: string;
|
|
253
|
+
/**
|
|
254
|
+
* Internal POS capability: fixed-duration candidates start from the stable
|
|
255
|
+
* context anchor's current minute instead of rounding up to ten minutes, and
|
|
256
|
+
* that minute remains selectable during before-start cutoff evaluation.
|
|
257
|
+
* Other callers keep the legacy alignment and strict second-level cutoff.
|
|
258
|
+
*/
|
|
259
|
+
useExactDurationCandidateMinute?: boolean;
|
|
260
|
+
/**
|
|
261
|
+
* Internal POS capability: allow explicit duration/start overrides to append
|
|
262
|
+
* a custom duration candidate for Session products. Fixed Session ranges are
|
|
263
|
+
* still returned unchanged. Callers outside the POS facade must leave this
|
|
264
|
+
* disabled.
|
|
265
|
+
*/
|
|
266
|
+
allowSessionCustomRanges?: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Internal POS capability: materialize candidates whose schedule date was
|
|
269
|
+
* explicitly excluded, while availability evaluation keeps them unavailable.
|
|
270
|
+
*/
|
|
271
|
+
allowExcludedScheduleDateOverride?: boolean;
|
|
246
272
|
}
|
|
247
273
|
export interface QueryAvailabilityBaseRequest {
|
|
248
274
|
productIds?: AvailabilityId[];
|
|
@@ -1128,7 +1128,7 @@ class RulesModule extends _BaseModule.BaseModule {
|
|
|
1128
1128
|
processedFlatItemsMap.set(flatItem._id, [{
|
|
1129
1129
|
...flatItem,
|
|
1130
1130
|
discount_list: isManualDiscount ? this.resolveDiscountListForManualOverride(flatItem.bundleItem?.discount_list || []) : this.filterDiscountListByType(flatItem.bundleItem?.discount_list || [], 'promotion'),
|
|
1131
|
-
price:
|
|
1131
|
+
price: flatItem.bundleItem.price,
|
|
1132
1132
|
bundle_selling_price: flatItem.bundleItem.bundle_selling_price ?? (isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price),
|
|
1133
1133
|
processed: true
|
|
1134
1134
|
}]);
|
package/lib/server/index.d.ts
CHANGED
package/lib/server/index.js
CHANGED
|
@@ -2152,10 +2152,12 @@ class Server {
|
|
|
2152
2152
|
|
|
2153
2153
|
/**
|
|
2154
2154
|
* 预约查询是否走本地:
|
|
2155
|
+
* - 日历周/月/资源视图通过 compact_fields 显式标识,始终走远端;
|
|
2155
2156
|
* - 当 sales_time_between 的开始和结束都不是今天时,走远端;
|
|
2156
2157
|
* - 其余情况走本地。
|
|
2157
2158
|
*/
|
|
2158
2159
|
shouldUseLocalBookingQuery(data) {
|
|
2160
|
+
if (data?.compact_fields === true) return false;
|
|
2159
2161
|
const range = data?.sales_time_between;
|
|
2160
2162
|
if (!Array.isArray(range) || range.length < 2) return true;
|
|
2161
2163
|
return !this.isRangeBothNotToday(range[0], range[1]);
|