@pisell/pisellos 2.2.321 → 2.2.323
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/modules/Order/index.d.ts +1 -1
- package/dist/modules/Order/utils.js +12 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +5 -0
- package/dist/server/index.js +3 -1
- package/dist/server/modules/order/types.d.ts +2 -0
- package/dist/server/modules/order/utils/filterOrders.js +20 -0
- package/dist/solution/BaseSales/index.d.ts +1 -0
- package/dist/solution/BaseSales/index.js +298 -209
- package/dist/solution/BaseSales/types.d.ts +3 -0
- package/dist/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
- package/dist/solution/BaseSales/utils/posDurationPricing.js +174 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
- package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -8
- package/dist/solution/BookingByStep/index.d.ts +3 -3
- package/dist/solution/BookingTicket/index.d.ts +1 -13
- package/dist/solution/UnifiedBookingSales/index.js +34 -16
- package/lib/modules/Order/index.d.ts +1 -1
- package/lib/modules/Order/utils.js +13 -0
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +5 -0
- package/lib/server/index.js +4 -1
- package/lib/server/modules/order/types.d.ts +2 -0
- package/lib/server/modules/order/utils/filterOrders.js +18 -0
- package/lib/solution/BaseSales/index.d.ts +1 -0
- package/lib/solution/BaseSales/index.js +95 -36
- package/lib/solution/BaseSales/types.d.ts +3 -0
- package/lib/solution/BaseSales/utils/posDurationPricing.d.ts +21 -0
- package/lib/solution/BaseSales/utils/posDurationPricing.js +133 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +2 -0
- package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +3 -3
- package/lib/solution/BookingTicket/index.d.ts +1 -13
- package/lib/solution/UnifiedBookingSales/index.js +23 -1
- package/package.json +1 -1
|
@@ -524,6 +524,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
524
524
|
getQuotationCustomerScopeInfo(): BaseSalesQuotationCustomerScopeInfo;
|
|
525
525
|
private hasSmartPricingStrategies;
|
|
526
526
|
shouldRecalculateProductBookingPricesForContextChange(params: BaseSalesPriceRecalculationContextChange): boolean;
|
|
527
|
+
private resolveProductBookingPriceGroups;
|
|
527
528
|
calculateProductBookingPrices(paramsList: BaseSalesCalculateProductBookingPriceParams[]): Promise<BaseSalesProductBookingPriceResult[]>;
|
|
528
529
|
addProductToOrder(product: Partial<BaseSalesOrderProduct> & BaseSalesOrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
|
|
529
530
|
updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
|
|
@@ -42,6 +42,7 @@ var _platform = require("../../utils/platform");
|
|
|
42
42
|
var _Quotation = require("../../modules/Quotation");
|
|
43
43
|
var _transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
|
|
44
44
|
var _quotationPrice = require("./utils/quotationPrice");
|
|
45
|
+
var _posDurationPricing = require("./utils/posDurationPricing");
|
|
45
46
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
46
47
|
const SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
|
|
47
48
|
const PAYMENT_METHODS_CHANGED_EVENT = 'payment:onPaymentMethodsChanged';
|
|
@@ -1091,6 +1092,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1091
1092
|
const shouldAlignSelectedVariantPrice = handledByOsServer && this.preferAuthoritativeProductQueryPrice();
|
|
1092
1093
|
return productIds.map((productId, index) => {
|
|
1093
1094
|
const authoritativeProduct = productId === null ? null : productsById.get(productId) || null;
|
|
1095
|
+
if (authoritativeProduct && (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos' && (params.strictDurationPricing || (0, _posDurationPricing.usesPosDurationPricing)(authoritativeProduct) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(selectedProducts[index]))) {
|
|
1096
|
+
return (0, _posDurationPricing.resolveDurationPricingProduct)(authoritativeProduct, selectedProducts[index]);
|
|
1097
|
+
}
|
|
1094
1098
|
if (!shouldAlignSelectedVariantPrice || !authoritativeProduct) return authoritativeProduct;
|
|
1095
1099
|
const selectedProduct = selectedProducts[index];
|
|
1096
1100
|
const selectedVariantId = this.getSelectedProductVariantId(selectedProduct);
|
|
@@ -1208,6 +1212,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1208
1212
|
return {
|
|
1209
1213
|
...product,
|
|
1210
1214
|
...authoritativeProduct,
|
|
1215
|
+
// An omitted current configuration clears a previous catalog/order snapshot.
|
|
1216
|
+
pricing_method: authoritativeProduct.pricing_method,
|
|
1211
1217
|
id: product.id ?? authoritativeProduct.id,
|
|
1212
1218
|
product_id: product.product_id ?? authoritativeProduct.product_id ?? authoritativeProduct.id,
|
|
1213
1219
|
product_variant_id: product.product_variant_id ?? authoritativeProduct.product_variant_id ?? 0,
|
|
@@ -4107,33 +4113,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4107
4113
|
return (0, _transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
|
|
4108
4114
|
}
|
|
4109
4115
|
async calculateProductBookingPrice(params) {
|
|
4110
|
-
const
|
|
4111
|
-
|
|
4112
|
-
const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
|
|
4113
|
-
await this.prepareProductPriceQueryContext(customerId);
|
|
4114
|
-
const channel = this.getPriceQueryChannel(params.channel);
|
|
4115
|
-
const [authoritativeProduct] = await this.resolveProductsForPriceQuery({
|
|
4116
|
-
priceQueries: [params],
|
|
4117
|
-
schedule: this.getPriceQuerySchedule(params),
|
|
4118
|
-
customerId,
|
|
4119
|
-
channel
|
|
4120
|
-
});
|
|
4121
|
-
const product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
|
|
4122
|
-
if (!useCustomerUserPricing) {
|
|
4123
|
-
await this.loadQuotationForPriceQuery({
|
|
4124
|
-
quotation,
|
|
4125
|
-
customer_id: customerId,
|
|
4126
|
-
channel
|
|
4127
|
-
});
|
|
4128
|
-
}
|
|
4129
|
-
return (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
4130
|
-
...params,
|
|
4131
|
-
channel,
|
|
4132
|
-
product,
|
|
4133
|
-
fallback_price: authoritativeProduct ? undefined : params.fallback_price,
|
|
4134
|
-
customer_id: customerId,
|
|
4135
|
-
quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? undefined : quotation
|
|
4136
|
-
});
|
|
4116
|
+
const [result] = await this.calculateProductBookingPrices([params]);
|
|
4117
|
+
return result;
|
|
4137
4118
|
}
|
|
4138
4119
|
getQuotationCustomerScopeInfo() {
|
|
4139
4120
|
const quotation = this.store.quotation;
|
|
@@ -4197,11 +4178,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4197
4178
|
}
|
|
4198
4179
|
return shouldRecalculate;
|
|
4199
4180
|
}
|
|
4200
|
-
async
|
|
4201
|
-
if (!paramsList.length) return [];
|
|
4202
|
-
const useCustomerUserPricing = this.isCustomerUserPriceQuery();
|
|
4203
|
-
const quotation = useCustomerUserPricing ? undefined : this.store.quotation;
|
|
4204
|
-
const currentOrderCustomerId = this.getCurrentOrderCustomerId();
|
|
4181
|
+
async resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId, strictDurationPricing = false) {
|
|
4205
4182
|
const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
|
|
4206
4183
|
const authoritativeProducts = paramsList.map(() => null);
|
|
4207
4184
|
const groups = new Map();
|
|
@@ -4219,22 +4196,68 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4219
4196
|
group.indices.push(index);
|
|
4220
4197
|
groups.set(groupKey, group);
|
|
4221
4198
|
});
|
|
4222
|
-
await
|
|
4199
|
+
await (0, _posDurationPricing.forEachPriceQueryGroup)(Array.from(groups.values()), async group => {
|
|
4223
4200
|
await this.prepareProductPriceQueryContext(group.customerId);
|
|
4224
4201
|
const priceQueries = group.indices.map(index => paramsList[index]);
|
|
4225
4202
|
const resolvedProducts = await this.resolveProductsForPriceQuery({
|
|
4226
4203
|
priceQueries,
|
|
4227
4204
|
schedule: group.schedule,
|
|
4228
4205
|
customerId: group.customerId,
|
|
4229
|
-
channel: group.channel
|
|
4206
|
+
channel: group.channel,
|
|
4207
|
+
strictDurationPricing
|
|
4230
4208
|
});
|
|
4231
4209
|
group.indices.forEach((originalIndex, groupIndex) => {
|
|
4232
4210
|
authoritativeProducts[originalIndex] = resolvedProducts[groupIndex] || null;
|
|
4233
4211
|
});
|
|
4234
|
-
}));
|
|
4212
|
+
}, (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos' ? 4 : groups.size);
|
|
4213
|
+
return authoritativeProducts;
|
|
4214
|
+
}
|
|
4215
|
+
async calculateProductBookingPrices(paramsList) {
|
|
4216
|
+
if (!paramsList.length) return [];
|
|
4217
|
+
const useCustomerUserPricing = this.isCustomerUserPriceQuery();
|
|
4218
|
+
const isPos = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos';
|
|
4219
|
+
const quotation = useCustomerUserPricing ? undefined : this.store.quotation;
|
|
4220
|
+
const currentOrderCustomerId = this.getCurrentOrderCustomerId();
|
|
4221
|
+
const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
|
|
4222
|
+
const authoritativeProducts = await this.resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId);
|
|
4223
|
+
const plans = paramsList.map((params, index) => {
|
|
4224
|
+
if (!isPos) return null;
|
|
4225
|
+
const product = authoritativeProducts[index];
|
|
4226
|
+
if (!product && ((0, _posDurationPricing.usesPosDurationPricing)(params.product) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(params.product))) {
|
|
4227
|
+
throw (0, _posDurationPricing.durationPricingUnavailable)('The authoritative product is unavailable for duration pricing.');
|
|
4228
|
+
}
|
|
4229
|
+
// Read configuration from the response itself: an omitted field must not inherit an old snapshot.
|
|
4230
|
+
return product && (0, _posDurationPricing.usesPosDurationPricing)(product) ? (0, _posDurationPricing.buildPosDurationPricingPlan)(params, product) : null;
|
|
4231
|
+
});
|
|
4232
|
+
const segmentQueries = [];
|
|
4233
|
+
const segmentQueryIndices = plans.map((plan, index) => plan?.segments.slice(1).map(segment => {
|
|
4234
|
+
const queryIndex = segmentQueries.length;
|
|
4235
|
+
segmentQueries.push({
|
|
4236
|
+
...paramsList[index],
|
|
4237
|
+
product: {
|
|
4238
|
+
...paramsList[index].product,
|
|
4239
|
+
product_bundle: undefined
|
|
4240
|
+
},
|
|
4241
|
+
booking: {
|
|
4242
|
+
...paramsList[index].booking,
|
|
4243
|
+
start_date: segment.start.slice(0, 10),
|
|
4244
|
+
start_time: segment.start.slice(11),
|
|
4245
|
+
end_date: segment.end.slice(0, 10),
|
|
4246
|
+
end_time: segment.end.slice(11)
|
|
4247
|
+
},
|
|
4248
|
+
duration: undefined,
|
|
4249
|
+
fallback_price: undefined
|
|
4250
|
+
});
|
|
4251
|
+
return queryIndex;
|
|
4252
|
+
}) || []);
|
|
4253
|
+
const segmentProducts = await this.resolveProductBookingPriceGroups(segmentQueries, currentOrderCustomerId, true);
|
|
4254
|
+
if (segmentProducts.some(product => !product)) {
|
|
4255
|
+
throw (0, _posDurationPricing.durationPricingUnavailable)('An authoritative product is missing for a billing unit.');
|
|
4256
|
+
}
|
|
4235
4257
|
if (!useCustomerUserPricing) {
|
|
4236
4258
|
const quotationContexts = new Map();
|
|
4237
4259
|
paramsList.forEach((params, index) => {
|
|
4260
|
+
if (plans[index]) return;
|
|
4238
4261
|
const channel = resolvedChannels[index];
|
|
4239
4262
|
const key = channel || '';
|
|
4240
4263
|
if (quotationContexts.has(key)) return;
|
|
@@ -4254,14 +4277,50 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4254
4277
|
const product = this.mergeProductForPriceQuery(productInput, authoritativeProduct);
|
|
4255
4278
|
const customerId = params.customer_id ?? currentOrderCustomerId;
|
|
4256
4279
|
const channel = resolvedChannels[index];
|
|
4257
|
-
|
|
4280
|
+
const plan = plans[index];
|
|
4281
|
+
if (plan) {
|
|
4282
|
+
const unitProducts = [authoritativeProduct, ...segmentQueryIndices[index].map(queryIndex => segmentProducts[queryIndex])];
|
|
4283
|
+
const prices = unitProducts.map((unitProduct, unitIndex) => (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
4284
|
+
...params,
|
|
4285
|
+
channel,
|
|
4286
|
+
product: this.mergeProductForPriceQuery(unitIndex === 0 ? productInput : {
|
|
4287
|
+
...productInput,
|
|
4288
|
+
product_bundle: undefined
|
|
4289
|
+
}, unitProduct),
|
|
4290
|
+
booking: {
|
|
4291
|
+
...params.booking,
|
|
4292
|
+
start_date: plan.segments[unitIndex].start.slice(0, 10),
|
|
4293
|
+
start_time: plan.segments[unitIndex].start.slice(11)
|
|
4294
|
+
},
|
|
4295
|
+
duration: undefined,
|
|
4296
|
+
fallback_price: undefined,
|
|
4297
|
+
customer_id: customerId,
|
|
4298
|
+
quotation: undefined
|
|
4299
|
+
}));
|
|
4300
|
+
return (0, _posDurationPricing.combinePosDurationPrices)(plan, prices);
|
|
4301
|
+
}
|
|
4302
|
+
const changedToFixed = isPos && ((0, _posDurationPricing.usesPosDurationPricing)(productInput) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(productInput)) && authoritativeProduct && !(0, _posDurationPricing.usesPosDurationPricing)(authoritativeProduct);
|
|
4303
|
+
// A switch to Days can explicitly request the existing per-day quotation path.
|
|
4304
|
+
// Discard the old minute basis, but do not erase that independent legacy input.
|
|
4305
|
+
const keepLegacyDayDuration = changedToFixed && ['day', 'days'].includes(String(authoritativeProduct?.duration?.type || '').trim().toLowerCase()) && ['day', 'days'].includes(String(params.duration?.type || '').trim().toLowerCase());
|
|
4306
|
+
const result = (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
4258
4307
|
...params,
|
|
4308
|
+
...(changedToFixed && !keepLegacyDayDuration ? {
|
|
4309
|
+
duration: undefined
|
|
4310
|
+
} : {}),
|
|
4259
4311
|
channel,
|
|
4260
4312
|
product,
|
|
4261
4313
|
fallback_price: authoritativeProduct ? undefined : params.fallback_price,
|
|
4262
4314
|
customer_id: customerId,
|
|
4263
4315
|
quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? undefined : quotation
|
|
4264
4316
|
});
|
|
4317
|
+
return changedToFixed ? {
|
|
4318
|
+
...result,
|
|
4319
|
+
pricing_method: {
|
|
4320
|
+
type: 'fixed_price'
|
|
4321
|
+
},
|
|
4322
|
+
duration: undefined
|
|
4323
|
+
} : result;
|
|
4265
4324
|
});
|
|
4266
4325
|
}
|
|
4267
4326
|
async addProductToOrder(product, booking, options) {
|
|
@@ -348,6 +348,9 @@ export interface BaseSalesProductBookingPriceResult {
|
|
|
348
348
|
unit_price: string;
|
|
349
349
|
total_price: string;
|
|
350
350
|
quantity: number;
|
|
351
|
+
pricing_method?: {
|
|
352
|
+
type: 'fixed_price' | 'duration_based';
|
|
353
|
+
};
|
|
351
354
|
duration?: BaseSalesQuotationDurationConfig;
|
|
352
355
|
quotation_shelf_id: number;
|
|
353
356
|
segments: BaseSalesProductBookingPriceSegment[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult, BaseSalesQuotationDurationConfig } from '../types';
|
|
2
|
+
export interface PosDurationPricingPlan {
|
|
3
|
+
duration: BaseSalesQuotationDurationConfig;
|
|
4
|
+
segments: Array<{
|
|
5
|
+
start: string;
|
|
6
|
+
end: string;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
export declare function durationPricingUnavailable(message: string): Error & {
|
|
10
|
+
code: string;
|
|
11
|
+
};
|
|
12
|
+
export declare function hasDurationBasedPricing(product: Record<string, any> | null | undefined): boolean;
|
|
13
|
+
/** Days/Flexible retain their existing quotation behavior. */
|
|
14
|
+
export declare function usesPosDurationPricing(product: Record<string, any> | null | undefined): boolean;
|
|
15
|
+
/** A hydrated catalog can already be fixed while its order/quote still contains an applied duration price. */
|
|
16
|
+
export declare function hasAppliedPosDurationPricing(product: Record<string, any> | null | undefined): boolean;
|
|
17
|
+
export declare function buildPosDurationPricingPlan(params: BaseSalesCalculateProductBookingPriceParams, product: Record<string, any>): PosDurationPricingPlan;
|
|
18
|
+
/** Never use a previously accumulated order price as one unit's fallback. */
|
|
19
|
+
export declare function resolveDurationPricingProduct(product: Record<string, any>, selected: Record<string, any>): Record<string, any>;
|
|
20
|
+
export declare function combinePosDurationPrices(plan: PosDurationPricingPlan, prices: BaseSalesProductBookingPriceResult[]): BaseSalesProductBookingPriceResult;
|
|
21
|
+
export declare function forEachPriceQueryGroup<T>(groups: T[], resolve: (group: T) => Promise<void>, concurrency: number): Promise<void>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildPosDurationPricingPlan = buildPosDurationPricingPlan;
|
|
7
|
+
exports.combinePosDurationPrices = combinePosDurationPrices;
|
|
8
|
+
exports.durationPricingUnavailable = durationPricingUnavailable;
|
|
9
|
+
exports.forEachPriceQueryGroup = forEachPriceQueryGroup;
|
|
10
|
+
exports.hasAppliedPosDurationPricing = hasAppliedPosDurationPricing;
|
|
11
|
+
exports.hasDurationBasedPricing = hasDurationBasedPricing;
|
|
12
|
+
exports.resolveDurationPricingProduct = resolveDurationPricingProduct;
|
|
13
|
+
exports.usesPosDurationPricing = usesPosDurationPricing;
|
|
14
|
+
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
15
|
+
var _decimal = _interopRequireDefault(require("decimal.js"));
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
function durationPricingUnavailable(message) {
|
|
18
|
+
return Object.assign(new Error(message), {
|
|
19
|
+
code: 'DURATION_PRICING_UNAVAILABLE'
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function hasDurationBasedPricing(product) {
|
|
23
|
+
return product?.pricing_method?.type === 'duration_based';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Days/Flexible retain their existing quotation behavior. */
|
|
27
|
+
function usesPosDurationPricing(product) {
|
|
28
|
+
const type = String(product?.duration?.type || '').trim().toLowerCase();
|
|
29
|
+
return hasDurationBasedPricing(product) && !['day', 'days', 'flexible'].includes(type);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A hydrated catalog can already be fixed while its order/quote still contains an applied duration price. */
|
|
33
|
+
function hasAppliedPosDurationPricing(product) {
|
|
34
|
+
return usesPosDurationPricing(product?._extend?.bookingPriceQuote) || usesPosDurationPricing(product?._extend?.bookingPrice?.quote) || usesPosDurationPricing(product?.metadata);
|
|
35
|
+
}
|
|
36
|
+
function bookingDateTime(date, time) {
|
|
37
|
+
const dateText = typeof date === 'string' ? date.trim() : '';
|
|
38
|
+
const timeText = typeof time === 'string' ? time.trim() : '';
|
|
39
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(dateText) || !/^\d{2}:\d{2}(?::\d{2})?$/.test(timeText)) {
|
|
40
|
+
throw durationPricingUnavailable('A valid booking start and end are required for duration pricing.');
|
|
41
|
+
}
|
|
42
|
+
const text = `${dateText} ${timeText.length === 5 ? `${timeText}:00` : timeText}`;
|
|
43
|
+
const value = (0, _dayjs.default)(text);
|
|
44
|
+
if (!value.isValid() || value.format('YYYY-MM-DD HH:mm:ss') !== text) {
|
|
45
|
+
throw durationPricingUnavailable('The booking time is invalid for duration pricing.');
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
function buildPosDurationPricingPlan(params, product) {
|
|
50
|
+
const type = String(product.duration?.type || '').trim().toLowerCase();
|
|
51
|
+
const value = Number(product.duration?.value);
|
|
52
|
+
const minutes = ['hour', 'hours'].includes(type) ? value * 60 : value;
|
|
53
|
+
if (!['minute', 'minutes', 'hour', 'hours'].includes(type) || !Number.isFinite(minutes) || minutes <= 0) {
|
|
54
|
+
throw durationPricingUnavailable('A positive fixed billing duration is required.');
|
|
55
|
+
}
|
|
56
|
+
const start = bookingDateTime(params.booking?.start_date, params.booking?.start_time);
|
|
57
|
+
const end = bookingDateTime(params.booking?.end_date, params.booking?.end_time);
|
|
58
|
+
const count = end.diff(start) / (minutes * 60_000);
|
|
59
|
+
if (!Number.isInteger(count) || count < 1 || count > 10_000) {
|
|
60
|
+
throw durationPricingUnavailable('The booking duration must be a whole multiple of its billing duration.');
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
duration: {
|
|
64
|
+
type: 'minutes',
|
|
65
|
+
value: minutes
|
|
66
|
+
},
|
|
67
|
+
segments: Array.from({
|
|
68
|
+
length: count
|
|
69
|
+
}, (_, index) => ({
|
|
70
|
+
start: start.add(index * minutes, 'minute').format('YYYY-MM-DD HH:mm:ss'),
|
|
71
|
+
end: start.add((index + 1) * minutes, 'minute').format('YYYY-MM-DD HH:mm:ss')
|
|
72
|
+
}))
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Never use a previously accumulated order price as one unit's fallback. */
|
|
77
|
+
function resolveDurationPricingProduct(product, selected) {
|
|
78
|
+
const variantId = Number(selected.product_variant_id ?? selected.variant_id ?? 0);
|
|
79
|
+
const authoritativeVariantId = Number(product.product_variant_id ?? product.variant_id ?? 0);
|
|
80
|
+
const variant = variantId > 0 && Array.isArray(product.variant) ? product.variant.find(item => Number(item?.id) === variantId) : undefined;
|
|
81
|
+
if (variantId > 0 && !variant && authoritativeVariantId !== variantId) {
|
|
82
|
+
throw durationPricingUnavailable('The selected SKU is missing from the authoritative price response.');
|
|
83
|
+
}
|
|
84
|
+
const appliedFields = product._dataVariant?.appliedFields;
|
|
85
|
+
const hasAppliedPrice = Array.isArray(appliedFields) && ['price', 'selling_price', 'original_price', 'base_price'].some(field => appliedFields.includes(field));
|
|
86
|
+
const priceSource = variantId > 0 && authoritativeVariantId !== variantId && !hasAppliedPrice ? variant : product;
|
|
87
|
+
const price = priceSource?.price ?? priceSource?.selling_price ?? priceSource?.base_price ?? priceSource?.original_price;
|
|
88
|
+
if (!(typeof price === 'number' || typeof price === 'string' && price.trim() !== '') || !Number.isFinite(Number(price)) || Number(price) < 0) {
|
|
89
|
+
throw durationPricingUnavailable('An authoritative price is required for every billing unit.');
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
...product,
|
|
93
|
+
price
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function combinePosDurationPrices(plan, prices) {
|
|
97
|
+
if (prices.length !== plan.segments.length || prices.length === 0) {
|
|
98
|
+
throw durationPricingUnavailable('The duration price is incomplete.');
|
|
99
|
+
}
|
|
100
|
+
const unitPrice = prices.reduce((sum, price) => sum.plus(price.unit_price), new _decimal.default(0));
|
|
101
|
+
return {
|
|
102
|
+
...prices[0],
|
|
103
|
+
pricing_method: {
|
|
104
|
+
type: 'duration_based'
|
|
105
|
+
},
|
|
106
|
+
duration: plan.duration,
|
|
107
|
+
unit_price: unitPrice.toFixed(2),
|
|
108
|
+
total_price: unitPrice.times(prices[0].quantity).toFixed(2),
|
|
109
|
+
quotation_shelf_id: prices.find(price => price.quotation_shelf_id)?.quotation_shelf_id || 0,
|
|
110
|
+
segments: prices.map((price, index) => ({
|
|
111
|
+
...price.segments[0],
|
|
112
|
+
start_datetime: plan.segments[index].start,
|
|
113
|
+
end_datetime: plan.segments[index].end,
|
|
114
|
+
time_point: plan.segments[index].start,
|
|
115
|
+
unit_price: price.unit_price,
|
|
116
|
+
total_price: price.unit_price,
|
|
117
|
+
quantity: 1
|
|
118
|
+
})),
|
|
119
|
+
// Options are composed by the caller; bundle pricing belongs to the first unit only.
|
|
120
|
+
product_bundle: prices[0].product_bundle
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
async function forEachPriceQueryGroup(groups, resolve, concurrency) {
|
|
124
|
+
let next = 0;
|
|
125
|
+
await Promise.all(Array.from({
|
|
126
|
+
length: Math.min(groups.length, concurrency)
|
|
127
|
+
}, async () => {
|
|
128
|
+
while (next < groups.length) {
|
|
129
|
+
const group = groups[next++];
|
|
130
|
+
await resolve(group);
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
@@ -55,6 +55,8 @@ export interface TransformBaseProductToOrderProductParams {
|
|
|
55
55
|
fallbackProductId?: number | string | null;
|
|
56
56
|
sourceProduct?: ProductData | Record<string, any> | null;
|
|
57
57
|
sourceItem?: ProductData | Record<string, any> | null;
|
|
58
|
+
/** Validated booking quote's pre-discount main price, excluding options/bundles. */
|
|
59
|
+
quotedSourceProductPrice?: number | string;
|
|
58
60
|
}
|
|
59
61
|
export type BaseProductOrderProductInput = Partial<OrderProduct> & OrderProductIdentity & {
|
|
60
62
|
_origin?: Record<string, any>;
|
|
@@ -156,7 +156,7 @@ function transformBaseProductToOrderProduct(params) {
|
|
|
156
156
|
// 售价仍由 line_total - bundle 推导。
|
|
157
157
|
const catalogSourcePrice = matchedVariant?.price ?? matchedVariant?.base_price ?? origin?.price ?? origin?.base_price ?? sourceProduct?.price ?? sourceProduct?.selling_price ?? sourceProduct?.base_price;
|
|
158
158
|
const weighedSourcePrice = (0, _weighedProduct.resolveWeighedSourcePrice)(payload.product_sku ?? origin.product_sku, payload._extend?.weighing ?? origin._extend?.weighing);
|
|
159
|
-
const sourceProductPrice = toPriceString(weighedSourcePrice ?? (hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice), '0.00');
|
|
159
|
+
const sourceProductPrice = toPriceString(params.quotedSourceProductPrice ?? weighedSourcePrice ?? (hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice), '0.00');
|
|
160
160
|
const explicitLineTotal = payload.line_total ?? payload.total ?? payload._extend?.total;
|
|
161
161
|
const hasExplicitLineTotal = Number.isFinite(Number(explicitLineTotal));
|
|
162
162
|
const lineCompositeTotal = toPriceString(explicitLineTotal, sourceProductPrice);
|
|
@@ -328,7 +328,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
328
328
|
date: string;
|
|
329
329
|
status: string;
|
|
330
330
|
week: string;
|
|
331
|
-
weekNum: 0 |
|
|
331
|
+
weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
|
|
332
332
|
}[]>;
|
|
333
333
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
334
334
|
private getScheduleDataByIds;
|
|
@@ -347,7 +347,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
347
347
|
count: number;
|
|
348
348
|
left: number;
|
|
349
349
|
summaryCount: number;
|
|
350
|
-
status: "
|
|
350
|
+
status: "lots_of_space" | "filling_up_fast" | "sold_out";
|
|
351
351
|
}[];
|
|
352
352
|
/**
|
|
353
353
|
* 找到多个资源的公共可用时间段
|
|
@@ -375,7 +375,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
375
375
|
};
|
|
376
376
|
setOtherData(key: string, value: any): void;
|
|
377
377
|
getOtherData(key: string): any;
|
|
378
|
-
getProductTypeById(id: number): Promise<"
|
|
378
|
+
getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
|
|
379
379
|
/**
|
|
380
380
|
* 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
|
|
381
381
|
*
|
|
@@ -485,19 +485,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
485
485
|
* 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
|
|
486
486
|
* 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
|
|
487
487
|
*/
|
|
488
|
-
decideAddProduct(item: any, options?: Partial<AddProductDecideContext>):
|
|
489
|
-
action: "reloadCatalog";
|
|
490
|
-
} | {
|
|
491
|
-
action: "add";
|
|
492
|
-
cacheItem: any;
|
|
493
|
-
} | {
|
|
494
|
-
action: "requiresDetail";
|
|
495
|
-
payload: AddProductRequiresDetailPayload;
|
|
496
|
-
} | {
|
|
497
|
-
action: "requiresBookingEdit";
|
|
498
|
-
cacheItem: any;
|
|
499
|
-
payload: import("./utils/addProductDecision").AddProductRequiresBookingEditPayload;
|
|
500
|
-
};
|
|
488
|
+
decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
|
|
501
489
|
/** 规格弹窗 callback 后的第二段决策。 */
|
|
502
490
|
decideAfterDetail(cacheItem: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
|
|
503
491
|
/**
|
|
@@ -2375,6 +2375,17 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2375
2375
|
}
|
|
2376
2376
|
buildUnifiedOrderProduct(sourceProduct, ownershipKey, product) {
|
|
2377
2377
|
const normalizedProductRaw = product?.raw || {};
|
|
2378
|
+
const bookingQuote = sourceProduct._extend?.bookingPriceQuote;
|
|
2379
|
+
const isPos = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos';
|
|
2380
|
+
const quoteMethod = isPos ? bookingQuote?.pricing_method?.type : undefined;
|
|
2381
|
+
const hasDurationQuote = quoteMethod === 'duration_based';
|
|
2382
|
+
const quoteSourcePrice = bookingQuote?.sourceUnitPrice;
|
|
2383
|
+
const quoteDuration = bookingQuote?.duration;
|
|
2384
|
+
if (hasDurationQuote && (quoteSourcePrice === undefined || quoteSourcePrice === null || quoteSourcePrice === '' || !Number.isFinite(Number(quoteSourcePrice)) || Number(quoteSourcePrice) < 0 || quoteDuration?.type !== 'minutes' || !Number.isFinite(Number(quoteDuration.value)) || Number(quoteDuration.value) <= 0)) {
|
|
2385
|
+
throw Object.assign(new Error('按时长计价结果无效,请重新选择预约时间。'), {
|
|
2386
|
+
code: 'DURATION_PRICING_UNAVAILABLE'
|
|
2387
|
+
});
|
|
2388
|
+
}
|
|
2378
2389
|
const quotationShelfId = sourceProduct._extend?.quotation_shelf_id ?? sourceProduct.quotation_shelf_id ?? sourceProduct.metadata?.quotation_shelf_id;
|
|
2379
2390
|
const orderProduct = this.transformBaseProductToOrderProduct({
|
|
2380
2391
|
payload: {
|
|
@@ -2389,7 +2400,10 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2389
2400
|
[ownershipKey]: true
|
|
2390
2401
|
}
|
|
2391
2402
|
},
|
|
2392
|
-
sourceProduct
|
|
2403
|
+
sourceProduct,
|
|
2404
|
+
...(hasDurationQuote ? {
|
|
2405
|
+
quotedSourceProductPrice: quoteSourcePrice
|
|
2406
|
+
} : {})
|
|
2393
2407
|
});
|
|
2394
2408
|
if (orderProduct && typeof orderProduct === 'object') {
|
|
2395
2409
|
// BaseSales may rebuild metadata from its price source. Stamp ownership and the selected
|
|
@@ -2397,6 +2411,14 @@ class UnifiedBookingSalesImpl extends _BookingTicket.BookingTicket {
|
|
|
2397
2411
|
orderProduct.metadata = {
|
|
2398
2412
|
...(orderProduct.metadata || {}),
|
|
2399
2413
|
[ownershipKey]: true,
|
|
2414
|
+
...(hasDurationQuote || quoteMethod === 'fixed_price' ? {
|
|
2415
|
+
pricing_method: {
|
|
2416
|
+
type: quoteMethod
|
|
2417
|
+
},
|
|
2418
|
+
duration: hasDurationQuote ? {
|
|
2419
|
+
...quoteDuration
|
|
2420
|
+
} : undefined
|
|
2421
|
+
} : {}),
|
|
2400
2422
|
...(quotationShelfId !== undefined ? {
|
|
2401
2423
|
quotation_shelf_id: quotationShelfId
|
|
2402
2424
|
} : {})
|