@pisell/pisellos 2.2.322 → 2.2.324
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inventory/index.d.ts +92 -0
- package/dist/inventory/index.js +509 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -9
- package/dist/modules/BookingContext/index.d.ts +2 -2
- package/dist/modules/BookingContext/index.js +55 -25
- package/dist/modules/BookingContext/types.d.ts +2 -0
- package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
- package/dist/modules/BookingContext/utils/index.d.ts +1 -0
- package/dist/modules/BookingContext/utils/index.js +1 -0
- package/dist/modules/BookingContext/utils/productExtend.d.ts +20 -1
- package/dist/modules/BookingContext/utils/productExtend.js +122 -29
- package/dist/modules/Date/index.d.ts +1 -1
- package/dist/modules/Date/index.js +60 -14
- package/dist/modules/Date/types.d.ts +5 -0
- package/dist/modules/Discount/index.js +1 -0
- package/dist/modules/OpenData/index.d.ts +1 -0
- package/dist/modules/OpenData/index.js +1 -0
- package/dist/modules/OpenData/salesSettings.d.ts +32 -0
- package/dist/modules/OpenData/salesSettings.js +80 -0
- package/dist/modules/OpenData/types.d.ts +16 -0
- package/dist/modules/OpenData/utils.d.ts +1 -1
- package/dist/modules/OpenData/utils.js +3 -2
- package/dist/modules/Order/index.d.ts +54 -11
- package/dist/modules/Order/index.js +2699 -1411
- package/dist/modules/Order/types.d.ts +43 -5
- package/dist/modules/Order/types.js +4 -0
- package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/dist/modules/Order/unpaidAmountGap.js +72 -0
- package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
- package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
- package/dist/modules/Order/utils.d.ts +3 -1
- package/dist/modules/Order/utils.js +18 -3
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +5 -0
- package/dist/modules/ProductList/clientDataVariants.js +6 -2
- package/dist/modules/ProductList/index.d.ts +2 -0
- package/dist/modules/ProductList/index.js +161 -51
- package/dist/modules/ResourcePlanner/planner.js +58 -2
- package/dist/modules/ResourcePlanner/types.d.ts +13 -0
- package/dist/modules/Rules/index.d.ts +2 -0
- package/dist/modules/Rules/index.js +58 -39
- package/dist/modules/Schedule/index.d.ts +7 -1
- package/dist/modules/Schedule/index.js +155 -39
- package/dist/modules/Schedule/types.d.ts +2 -0
- package/dist/modules/bookingReadValidation.d.ts +6 -0
- package/dist/modules/bookingReadValidation.js +72 -0
- package/dist/plugins/request.d.ts +2 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +1312 -1154
- package/dist/server/modules/order/index.js +2 -1
- package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/dist/shared/receipt/small-ticket.d.ts +4 -0
- package/dist/shared/receipt/small-ticket.js +70 -12
- package/dist/solution/BaseSales/index.d.ts +40 -5
- package/dist/solution/BaseSales/index.js +1939 -1484
- package/dist/solution/BaseSales/types.d.ts +4 -0
- package/dist/solution/BaseSales/types.js +1 -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 +16 -2
- package/dist/solution/BookingByStep/index.js +676 -361
- package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/dist/solution/BookingByStep/utils/resources.js +117 -76
- package/dist/solution/BookingTicket/index.d.ts +2 -2
- package/dist/solution/BookingTicket/index.js +249 -135
- package/dist/solution/BookingTicket/types.d.ts +14 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.js +39 -11
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
- package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +88 -0
- package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/dist/solution/OrderInvoicePreview/index.js +14 -8
- package/dist/solution/ScanOrder/index.d.ts +2 -0
- package/dist/solution/ScanOrder/index.js +166 -67
- package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/dist/solution/ScanOrder/menuAvailability.js +363 -0
- package/dist/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
- package/dist/solution/UnifiedBookingSales/catalogQueryBatch.js +202 -0
- package/dist/solution/UnifiedBookingSales/index.d.ts +96 -4
- package/dist/solution/UnifiedBookingSales/index.js +3391 -1176
- package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
- package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +4 -0
- package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
- package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
- package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
- package/dist/solution/UnifiedBookingSales/types.d.ts +71 -2
- package/dist/solution/UnifiedBookingSales/types.js +7 -1
- package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
- package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +283 -0
- package/dist/utils/platform.d.ts +2 -0
- package/dist/utils/platform.js +6 -0
- package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
- package/dist/utils/pos-receipt-auto-print.js +14 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +12 -0
- package/lib/inventory/index.d.ts +92 -0
- package/lib/inventory/index.js +287 -0
- package/lib/model/strategy/adapter/promotion/index.js +1 -46
- package/lib/modules/BookingContext/index.d.ts +2 -2
- package/lib/modules/BookingContext/index.js +42 -10
- package/lib/modules/BookingContext/types.d.ts +2 -0
- package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
- package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
- package/lib/modules/BookingContext/utils/index.d.ts +1 -0
- package/lib/modules/BookingContext/utils/index.js +11 -0
- package/lib/modules/BookingContext/utils/productExtend.d.ts +20 -1
- package/lib/modules/BookingContext/utils/productExtend.js +96 -7
- package/lib/modules/Date/index.d.ts +1 -1
- package/lib/modules/Date/index.js +28 -5
- package/lib/modules/Date/types.d.ts +5 -0
- package/lib/modules/Discount/index.js +1 -0
- package/lib/modules/OpenData/index.d.ts +1 -0
- package/lib/modules/OpenData/index.js +12 -0
- package/lib/modules/OpenData/salesSettings.d.ts +32 -0
- package/lib/modules/OpenData/salesSettings.js +70 -0
- package/lib/modules/OpenData/types.d.ts +16 -0
- package/lib/modules/OpenData/utils.d.ts +1 -1
- package/lib/modules/OpenData/utils.js +3 -2
- package/lib/modules/Order/index.d.ts +54 -11
- package/lib/modules/Order/index.js +659 -80
- package/lib/modules/Order/types.d.ts +43 -5
- package/lib/modules/Order/types.js +2 -0
- package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
- package/lib/modules/Order/unpaidAmountGap.js +60 -0
- package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
- package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
- package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
- package/lib/modules/Order/utils.d.ts +3 -1
- package/lib/modules/Order/utils.js +19 -2
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +5 -0
- package/lib/modules/ProductList/clientDataVariants.js +6 -2
- package/lib/modules/ProductList/index.d.ts +2 -0
- package/lib/modules/ProductList/index.js +74 -0
- package/lib/modules/ResourcePlanner/planner.js +52 -1
- package/lib/modules/ResourcePlanner/types.d.ts +13 -0
- package/lib/modules/Rules/index.d.ts +2 -0
- package/lib/modules/Rules/index.js +25 -9
- package/lib/modules/Schedule/index.d.ts +7 -1
- package/lib/modules/Schedule/index.js +68 -4
- package/lib/modules/Schedule/types.d.ts +2 -0
- package/lib/modules/bookingReadValidation.d.ts +6 -0
- package/lib/modules/bookingReadValidation.js +56 -0
- package/lib/plugins/request.d.ts +2 -0
- package/lib/server/index.d.ts +5 -0
- package/lib/server/index.js +124 -16
- package/lib/server/modules/order/index.js +2 -1
- package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
- package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
- package/lib/shared/receipt/small-ticket.d.ts +4 -0
- package/lib/shared/receipt/small-ticket.js +63 -8
- package/lib/solution/BaseSales/index.d.ts +40 -5
- package/lib/solution/BaseSales/index.js +296 -43
- package/lib/solution/BaseSales/types.d.ts +4 -0
- package/lib/solution/BaseSales/types.js +1 -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 +16 -2
- package/lib/solution/BookingByStep/index.js +222 -14
- package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
- package/lib/solution/BookingByStep/utils/resources.js +25 -15
- package/lib/solution/BookingTicket/index.d.ts +2 -2
- package/lib/solution/BookingTicket/index.js +47 -4
- package/lib/solution/BookingTicket/types.d.ts +14 -2
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.js +37 -6
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
- package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +54 -0
- package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
- package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
- package/lib/solution/OrderInvoicePreview/index.js +7 -1
- package/lib/solution/ScanOrder/index.d.ts +2 -0
- package/lib/solution/ScanOrder/index.js +72 -2
- package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
- package/lib/solution/ScanOrder/menuAvailability.js +203 -0
- package/lib/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
- package/lib/solution/UnifiedBookingSales/catalogQueryBatch.js +109 -0
- package/lib/solution/UnifiedBookingSales/index.d.ts +96 -4
- package/lib/solution/UnifiedBookingSales/index.js +1339 -74
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
- package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +2 -0
- package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
- package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
- package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
- package/lib/solution/UnifiedBookingSales/types.d.ts +71 -2
- package/lib/solution/UnifiedBookingSales/types.js +4 -1
- package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
- package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +155 -0
- package/lib/utils/platform.d.ts +2 -0
- package/lib/utils/platform.js +7 -0
- package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
- package/lib/utils/pos-receipt-auto-print.js +13 -0
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ var _exportNames = {
|
|
|
7
7
|
BaseSalesImpl: true
|
|
8
8
|
};
|
|
9
9
|
exports.BaseSalesImpl = void 0;
|
|
10
|
+
var _inventory = require("../../inventory");
|
|
10
11
|
var _BaseModule = require("../../modules/BaseModule");
|
|
11
12
|
var _localEftposState = require("../../modules/Order/localEftposState");
|
|
12
13
|
var _types = require("./types");
|
|
@@ -39,9 +40,11 @@ var _orderCollectionIdentity = require("../../modules/Order/utils/orderCollectio
|
|
|
39
40
|
var _dayjs = _interopRequireDefault(require("dayjs"));
|
|
40
41
|
var _clientDataVariants = require("../../modules/ProductList/clientDataVariants");
|
|
41
42
|
var _platform = require("../../utils/platform");
|
|
43
|
+
var _posReceiptAutoPrint = require("../../utils/pos-receipt-auto-print");
|
|
42
44
|
var _Quotation = require("../../modules/Quotation");
|
|
43
45
|
var _transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
|
|
44
46
|
var _quotationPrice = require("./utils/quotationPrice");
|
|
47
|
+
var _posDurationPricing = require("./utils/posDurationPricing");
|
|
45
48
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
46
49
|
const SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
|
|
47
50
|
const PAYMENT_METHODS_CHANGED_EVENT = 'payment:onPaymentMethodsChanged';
|
|
@@ -511,6 +514,40 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
511
514
|
order: undefined
|
|
512
515
|
};
|
|
513
516
|
otherParams = {};
|
|
517
|
+
getInventory() {
|
|
518
|
+
return this.otherParams.inventory;
|
|
519
|
+
}
|
|
520
|
+
async prepareCheckout(signal) {
|
|
521
|
+
const inventory = this.getInventory();
|
|
522
|
+
const hooks = this.otherParams.checkoutHooks;
|
|
523
|
+
if (!inventory && !hooks?.beforeCheckout) return undefined;
|
|
524
|
+
if (!this.store.order) throw new Error('Order module is not ready');
|
|
525
|
+
return this.store.order.prepareCheckout(async items => {
|
|
526
|
+
const assertCurrent = () => {
|
|
527
|
+
if (signal?.aborted) throw Object.assign(new Error('Checkout cancelled'), {
|
|
528
|
+
name: 'AbortError'
|
|
529
|
+
});
|
|
530
|
+
if (inventory !== this.getInventory() || hooks !== this.otherParams.checkoutHooks) throw (0, _inventory.salesGuardError)('The sales context changed. Please try again.');
|
|
531
|
+
};
|
|
532
|
+
assertCurrent();
|
|
533
|
+
try {
|
|
534
|
+
await hooks?.beforeCheckout?.({
|
|
535
|
+
items,
|
|
536
|
+
signal
|
|
537
|
+
});
|
|
538
|
+
if (inventory) await inventory.refresh({
|
|
539
|
+
reason: 'checkout',
|
|
540
|
+
force: true,
|
|
541
|
+
signal
|
|
542
|
+
});
|
|
543
|
+
assertCurrent();
|
|
544
|
+
return inventory?.freezeCheckout(items);
|
|
545
|
+
} catch (error) {
|
|
546
|
+
if (error?.name === 'AbortError') throw error;
|
|
547
|
+
throw (0, _inventory.salesGuardError)(error instanceof Error ? error.message : String(error));
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
}
|
|
514
551
|
cacheId;
|
|
515
552
|
/**
|
|
516
553
|
* 由已在初始化阶段解析过设备短号的业务解决方案写入。
|
|
@@ -527,6 +564,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
527
564
|
// 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
|
|
528
565
|
currentSalesDetail = null;
|
|
529
566
|
discountConfigCacheKey = null;
|
|
567
|
+
discountConfigPrepareInFlight = null;
|
|
530
568
|
hasManualDiscountSelection = false;
|
|
531
569
|
reusedSharedSubModuleNames = new Set();
|
|
532
570
|
paymentMethodsCache = [];
|
|
@@ -539,6 +577,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
539
577
|
salesDetailHydrateQueue = Promise.resolve();
|
|
540
578
|
serverOrderChangeUnsubscribe = null;
|
|
541
579
|
paymentMethodsChangedUnsubscribe = null;
|
|
580
|
+
orderSessionChangedUnsubscribe = null;
|
|
542
581
|
serverOrderChangeHydrateInFlight = null;
|
|
543
582
|
queuedServerOrderChanges = [];
|
|
544
583
|
serverOrderChangeSyncEnabled = false;
|
|
@@ -699,6 +738,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
699
738
|
await this.getPaymentMethodsAsync();
|
|
700
739
|
});
|
|
701
740
|
}
|
|
741
|
+
registerOrderSessionChangeSync() {
|
|
742
|
+
this.orderSessionChangedUnsubscribe?.();
|
|
743
|
+
this.orderSessionChangedUnsubscribe = this.store.order?.effectsOn?.('onOrderSessionChanged', payload => this.effectsEmit(_types.BaseSalesHookNames.onOrderSessionChanged, payload)) || null;
|
|
744
|
+
}
|
|
702
745
|
async hydrateLatestLoadedSalesDetail(record, loadSequence, options) {
|
|
703
746
|
let hydratedSales = null;
|
|
704
747
|
let skippedBeforeHydrate = false;
|
|
@@ -1016,6 +1059,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1016
1059
|
products: [preparedProduct],
|
|
1017
1060
|
queryPayload: params.queryPayload,
|
|
1018
1061
|
handledByOsServer: false,
|
|
1062
|
+
...(params.menuList ? {
|
|
1063
|
+
menuList: params.menuList
|
|
1064
|
+
} : {}),
|
|
1019
1065
|
...(scheduleList ? {
|
|
1020
1066
|
scheduleList
|
|
1021
1067
|
} : {})
|
|
@@ -1071,6 +1117,14 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1071
1117
|
return productsById;
|
|
1072
1118
|
}
|
|
1073
1119
|
}
|
|
1120
|
+
|
|
1121
|
+
/** Opt-in subclasses may supply page-owned raw pools; ordinary sales keep remote fallback. */
|
|
1122
|
+
isVenueCatalogLocalPricingActive() {
|
|
1123
|
+
return false;
|
|
1124
|
+
}
|
|
1125
|
+
getVenueCatalogLocalPriceSource(_productId, _selectedProduct) {
|
|
1126
|
+
return undefined;
|
|
1127
|
+
}
|
|
1074
1128
|
async resolveProductsForPriceQuery(params) {
|
|
1075
1129
|
const selectedProducts = params.priceQueries.map(item => item.product || {});
|
|
1076
1130
|
const productIds = selectedProducts.map(product => this.getPriceQueryProductId(product));
|
|
@@ -1078,6 +1132,30 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1078
1132
|
if (!ids.length) {
|
|
1079
1133
|
return selectedProducts.map(() => null);
|
|
1080
1134
|
}
|
|
1135
|
+
|
|
1136
|
+
// An explicitly active Venue pool owns all its product reads. Missing raw data
|
|
1137
|
+
// or rules must fail visibly; never silently spend a second list/detail request.
|
|
1138
|
+
if (this.isVenueCatalogLocalPricingActive()) {
|
|
1139
|
+
const queryPayload = this.buildPriceQueryPayload({
|
|
1140
|
+
ids,
|
|
1141
|
+
schedule: params.schedule,
|
|
1142
|
+
customerId: params.customerId,
|
|
1143
|
+
channel: params.channel
|
|
1144
|
+
});
|
|
1145
|
+
return selectedProducts.map((selectedProduct, index) => {
|
|
1146
|
+
const source = productIds[index] == null ? undefined : this.getVenueCatalogLocalPriceSource(productIds[index], selectedProduct);
|
|
1147
|
+
const resolved = source && this.resolveLocalProductForPriceQuery({
|
|
1148
|
+
selectedProduct,
|
|
1149
|
+
rawProduct: source.product,
|
|
1150
|
+
menuList: source.menuList,
|
|
1151
|
+
queryPayload
|
|
1152
|
+
});
|
|
1153
|
+
if (!resolved) throw Object.assign(new Error('The complete venue product or pricing rules are not ready. Reload the catalog before continuing.'), {
|
|
1154
|
+
code: 'VENUE_LOCAL_PRICE_UNAVAILABLE'
|
|
1155
|
+
});
|
|
1156
|
+
return resolved;
|
|
1157
|
+
});
|
|
1158
|
+
}
|
|
1081
1159
|
const handledByOsServer = this.request ? (0, _clientDataVariants.isProductQueryHandledByOsServer)(this.core, this.request) : false;
|
|
1082
1160
|
const canUseLocalFastPath = this.isCustomerUserPriceQuery() && !handledByOsServer;
|
|
1083
1161
|
if (!canUseLocalFastPath) {
|
|
@@ -1091,6 +1169,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1091
1169
|
const shouldAlignSelectedVariantPrice = handledByOsServer && this.preferAuthoritativeProductQueryPrice();
|
|
1092
1170
|
return productIds.map((productId, index) => {
|
|
1093
1171
|
const authoritativeProduct = productId === null ? null : productsById.get(productId) || null;
|
|
1172
|
+
if (authoritativeProduct && (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos' && (params.strictDurationPricing || (0, _posDurationPricing.usesPosDurationPricing)(authoritativeProduct) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(selectedProducts[index]))) {
|
|
1173
|
+
return (0, _posDurationPricing.resolveDurationPricingProduct)(authoritativeProduct, selectedProducts[index]);
|
|
1174
|
+
}
|
|
1094
1175
|
if (!shouldAlignSelectedVariantPrice || !authoritativeProduct) return authoritativeProduct;
|
|
1095
1176
|
const selectedProduct = selectedProducts[index];
|
|
1096
1177
|
const selectedVariantId = this.getSelectedProductVariantId(selectedProduct);
|
|
@@ -1208,6 +1289,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1208
1289
|
return {
|
|
1209
1290
|
...product,
|
|
1210
1291
|
...authoritativeProduct,
|
|
1292
|
+
// An omitted current configuration clears a previous catalog/order snapshot.
|
|
1293
|
+
pricing_method: authoritativeProduct.pricing_method,
|
|
1211
1294
|
id: product.id ?? authoritativeProduct.id,
|
|
1212
1295
|
product_id: product.product_id ?? authoritativeProduct.product_id ?? authoritativeProduct.id,
|
|
1213
1296
|
product_variant_id: product.product_variant_id ?? authoritativeProduct.product_variant_id ?? 0,
|
|
@@ -1366,11 +1449,17 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1366
1449
|
return undefined;
|
|
1367
1450
|
}
|
|
1368
1451
|
}
|
|
1452
|
+
|
|
1453
|
+
/** Only solutions with a current POS business configuration opt into this receipt policy. */
|
|
1454
|
+
getPosReceiptAutoPrintPaymentStatuses() {
|
|
1455
|
+
return undefined;
|
|
1456
|
+
}
|
|
1369
1457
|
buildSubmitPayloadEnhancerWithOpenDataConfig(enhancePayload) {
|
|
1370
1458
|
const fulfillmentRefMode = this.getFulfillmentRefMode();
|
|
1371
1459
|
const invoiceLayoutConfig = this.getCachedInvoiceLayoutConfig();
|
|
1372
1460
|
const invoiceTemplateSettings = this.getCachedInvoiceTemplateSettings();
|
|
1373
|
-
|
|
1461
|
+
const receiptPaymentStatuses = this.getPosReceiptAutoPrintPaymentStatuses();
|
|
1462
|
+
if (!fulfillmentRefMode && !invoiceLayoutConfig && !invoiceTemplateSettings && receiptPaymentStatuses === undefined) {
|
|
1374
1463
|
return enhancePayload;
|
|
1375
1464
|
}
|
|
1376
1465
|
return (payload, ctx) => {
|
|
@@ -1385,6 +1474,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1385
1474
|
} : {}),
|
|
1386
1475
|
...(invoiceTemplateSettings ? {
|
|
1387
1476
|
[OS_INVOICE_TEMPLATE_SETTINGS_FIELD]: (0, _lodashEs.cloneDeep)(invoiceTemplateSettings)
|
|
1477
|
+
} : {}),
|
|
1478
|
+
...(receiptPaymentStatuses !== undefined ? {
|
|
1479
|
+
[_posReceiptAutoPrint.OS_POS_RECEIPT_AUTO_PRINT_PAYMENT_STATUSES_FIELD]: [...receiptPaymentStatuses]
|
|
1388
1480
|
} : {})
|
|
1389
1481
|
};
|
|
1390
1482
|
};
|
|
@@ -1401,12 +1493,35 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1401
1493
|
}
|
|
1402
1494
|
return (0, _types2.createModule)(moduleName, this.name);
|
|
1403
1495
|
}
|
|
1496
|
+
inventoryOrderHooks;
|
|
1404
1497
|
getSubModuleHooks(moduleName) {
|
|
1405
1498
|
const optionHooks = this.initializeOptions.hooks || {};
|
|
1406
1499
|
const otherHooks = this.otherParams.hooks || {};
|
|
1407
1500
|
if (moduleName === 'order') {
|
|
1408
1501
|
const directOrderHooks = optionHooks;
|
|
1409
|
-
|
|
1502
|
+
const hooks = optionHooks.order || this.otherParams.order?.hooks || otherHooks.order || (directOrderHooks.onBeforeMergeProductToOrder || directOrderHooks.onBeforeCartCommit ? directOrderHooks : undefined);
|
|
1503
|
+
const inventory = this.getInventory();
|
|
1504
|
+
if (!inventory) {
|
|
1505
|
+
this.inventoryOrderHooks = undefined;
|
|
1506
|
+
return hooks;
|
|
1507
|
+
}
|
|
1508
|
+
if (this.inventoryOrderHooks?.inventory === inventory && this.inventoryOrderHooks.base === hooks) {
|
|
1509
|
+
return this.inventoryOrderHooks.hooks;
|
|
1510
|
+
}
|
|
1511
|
+
const combined = {
|
|
1512
|
+
...hooks,
|
|
1513
|
+
onBeforeCartCommit: async context => {
|
|
1514
|
+
await hooks?.onBeforeCartCommit?.(context);
|
|
1515
|
+
if (inventory !== this.getInventory()) throw (0, _inventory.salesGuardError)('The sales context changed. Please try again.');
|
|
1516
|
+
inventory.validate(context.proposedItems, context.currentItems);
|
|
1517
|
+
}
|
|
1518
|
+
};
|
|
1519
|
+
this.inventoryOrderHooks = {
|
|
1520
|
+
inventory,
|
|
1521
|
+
base: hooks,
|
|
1522
|
+
hooks: combined
|
|
1523
|
+
};
|
|
1524
|
+
return combined;
|
|
1410
1525
|
}
|
|
1411
1526
|
return optionHooks[moduleName] || this.otherParams[moduleName]?.hooks || otherHooks[moduleName];
|
|
1412
1527
|
}
|
|
@@ -1454,7 +1569,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1454
1569
|
const nextSubModuleOtherParams = this.buildSubModuleOtherParams(moduleName);
|
|
1455
1570
|
await targetModule.updateOtherParams(nextSubModuleOtherParams, {
|
|
1456
1571
|
changedParams,
|
|
1457
|
-
cover
|
|
1572
|
+
cover,
|
|
1573
|
+
...(moduleName === 'order' ? {
|
|
1574
|
+
hooks: this.getSubModuleHooks(moduleName)
|
|
1575
|
+
} : {})
|
|
1458
1576
|
});
|
|
1459
1577
|
}));
|
|
1460
1578
|
}
|
|
@@ -1603,7 +1721,17 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1603
1721
|
}
|
|
1604
1722
|
return isChanged;
|
|
1605
1723
|
}
|
|
1606
|
-
|
|
1724
|
+
initialization;
|
|
1725
|
+
|
|
1726
|
+
/** Hosts can await readiness without changing Core's synchronous registration API. */
|
|
1727
|
+
whenInitialized() {
|
|
1728
|
+
return this.initialization || Promise.reject(new Error('Sales module is not registered'));
|
|
1729
|
+
}
|
|
1730
|
+
initialize(core, options = {}) {
|
|
1731
|
+
this.initialization = this.initializeSalesRuntime(core, options);
|
|
1732
|
+
return this.initialization;
|
|
1733
|
+
}
|
|
1734
|
+
async initializeSalesRuntime(core, options = {}) {
|
|
1607
1735
|
this.resetPickupTimingCache();
|
|
1608
1736
|
this.core = core;
|
|
1609
1737
|
this.initializeOptions = options || {};
|
|
@@ -1654,6 +1782,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1654
1782
|
await this.getPaymentMethodsAsync();
|
|
1655
1783
|
this.registerPaymentMethodsChangeSync();
|
|
1656
1784
|
this.registerServerOrderChangeSync();
|
|
1785
|
+
this.registerOrderSessionChangeSync();
|
|
1657
1786
|
this.core.effects.emit(`${this.name}:onInited`, {});
|
|
1658
1787
|
}
|
|
1659
1788
|
async destroy() {
|
|
@@ -1663,17 +1792,21 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1663
1792
|
this.serverOrderChangeUnsubscribe = null;
|
|
1664
1793
|
this.paymentMethodsChangedUnsubscribe?.();
|
|
1665
1794
|
this.paymentMethodsChangedUnsubscribe = null;
|
|
1666
|
-
|
|
1667
|
-
|
|
1795
|
+
this.orderSessionChangedUnsubscribe?.();
|
|
1796
|
+
this.orderSessionChangedUnsubscribe = null;
|
|
1797
|
+
for (const key of Object.keys(this.store)) {
|
|
1798
|
+
if (this.reusedSharedSubModuleNames.has(key)) continue;
|
|
1668
1799
|
const sub = this.store[key];
|
|
1669
1800
|
if (sub && typeof sub.destroy === 'function') {
|
|
1670
1801
|
try {
|
|
1671
|
-
|
|
1802
|
+
// A host may register a replacement after destroy resolves. Wait for
|
|
1803
|
+
// nested modules so their cleanup cannot unregister the replacement.
|
|
1804
|
+
await sub.destroy();
|
|
1672
1805
|
} catch (error) {
|
|
1673
1806
|
console.warn(`[BaseSales] 子模块 ${key} 销毁失败`, error);
|
|
1674
1807
|
}
|
|
1675
1808
|
}
|
|
1676
|
-
}
|
|
1809
|
+
}
|
|
1677
1810
|
this.currentSalesDetail = null;
|
|
1678
1811
|
this.paymentNumberDevicePrefix = null;
|
|
1679
1812
|
this.queuedServerOrderChanges = [];
|
|
@@ -1793,6 +1926,12 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1793
1926
|
const result = this.store.order?.getTempOrder() || null;
|
|
1794
1927
|
return result;
|
|
1795
1928
|
}
|
|
1929
|
+
getOrderSessionId() {
|
|
1930
|
+
return this.store.order?.getOrderSessionId?.() || null;
|
|
1931
|
+
}
|
|
1932
|
+
isOrderSessionCurrent(sessionId) {
|
|
1933
|
+
return this.store.order?.isOrderSessionCurrent?.(sessionId) || false;
|
|
1934
|
+
}
|
|
1796
1935
|
async replaceTempOrder(tempOrder, options) {
|
|
1797
1936
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
1798
1937
|
const nextTempOrder = await this.store.order.replaceTempOrder(tempOrder, options);
|
|
@@ -1994,7 +2133,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1994
2133
|
}
|
|
1995
2134
|
|
|
1996
2135
|
/**
|
|
1997
|
-
*
|
|
2136
|
+
* 清空 tempOrder 购物车行(products / bookings / discount_list)及整单折扣。
|
|
1998
2137
|
* 同步清空内存中的 salesDetail 商品/预约视图,避免编辑态仍读到旧 bookings。
|
|
1999
2138
|
*/
|
|
2000
2139
|
async clearOrderCartLines() {
|
|
@@ -2210,9 +2349,16 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2210
2349
|
const searchedDiscountIds = new Set(searchedDiscountList.map(discount => String(discount.id)));
|
|
2211
2350
|
let preparedDiscountList = [...searchedDiscountList, ...originalDiscountList.filter(discount => !searchedDiscountIds.has(String(discount.id)))];
|
|
2212
2351
|
if (customerId && customerId !== 1) {
|
|
2213
|
-
|
|
2352
|
+
const inFlight = this.discountConfigPrepareInFlight;
|
|
2353
|
+
// 客户刷新和商品查询共享配置准备;force 仅绕过已完成的缓存。
|
|
2354
|
+
if (inFlight?.key === discountConfigCacheKey && inFlight.epoch === requestEpoch) {
|
|
2355
|
+
preparedDiscountList = await inFlight.promise;
|
|
2356
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2357
|
+
} else if (!params?.force && this.discountConfigCacheKey === discountConfigCacheKey) {
|
|
2214
2358
|
preparedDiscountList = originalDiscountList;
|
|
2215
2359
|
} else {
|
|
2360
|
+
// 强制刷新失败后,下次普通加载也应重试,不能命中刷新前的缓存。
|
|
2361
|
+
this.discountConfigCacheKey = null;
|
|
2216
2362
|
const prepareConfigPromise = this.store.order.loadDiscountConfig({
|
|
2217
2363
|
customerId,
|
|
2218
2364
|
action: discountAction,
|
|
@@ -2221,11 +2367,28 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2221
2367
|
});
|
|
2222
2368
|
// OrderModule increments this epoch synchronously before its first await.
|
|
2223
2369
|
requestEpoch = this.store.order.getCustomerWalletPrepareConfigEpoch?.();
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2370
|
+
const prepareTask = {
|
|
2371
|
+
key: discountConfigCacheKey,
|
|
2372
|
+
epoch: requestEpoch,
|
|
2373
|
+
promise: prepareConfigPromise.then(async discountList => {
|
|
2374
|
+
if (!isCurrentRequest()) return discountList;
|
|
2375
|
+
await discountModule?.setOriginalDiscountList?.(discountList);
|
|
2376
|
+
if (isCurrentRequest()) {
|
|
2377
|
+
this.discountConfigCacheKey = discountConfigCacheKey;
|
|
2378
|
+
}
|
|
2379
|
+
return discountList;
|
|
2380
|
+
})
|
|
2381
|
+
};
|
|
2382
|
+
this.discountConfigPrepareInFlight = prepareTask;
|
|
2383
|
+
try {
|
|
2384
|
+
preparedDiscountList = await prepareTask.promise;
|
|
2385
|
+
} finally {
|
|
2386
|
+
// 旧请求结束时不能清掉客户/订单切换后创建的新任务。
|
|
2387
|
+
if (this.discountConfigPrepareInFlight === prepareTask) {
|
|
2388
|
+
this.discountConfigPrepareInFlight = null;
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2227
2391
|
if (!isCurrentRequest()) return getCurrentResult();
|
|
2228
|
-
this.discountConfigCacheKey = discountConfigCacheKey;
|
|
2229
2392
|
}
|
|
2230
2393
|
}
|
|
2231
2394
|
if (this.isActiveVirtualSettlementOrder(tempOrder)) {
|
|
@@ -2441,10 +2604,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2441
2604
|
}
|
|
2442
2605
|
await discountModule.setDiscountList(params.discountList);
|
|
2443
2606
|
}
|
|
2444
|
-
async scanPromotionCode(code, customerId) {
|
|
2607
|
+
async scanPromotionCode(code, customerId, options) {
|
|
2445
2608
|
try {
|
|
2446
2609
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2447
|
-
const raw = await this.store.order.scanCode(code, customerId);
|
|
2610
|
+
const raw = await this.store.order.scanCode(code, customerId, options);
|
|
2448
2611
|
if (raw.isAvailable) {
|
|
2449
2612
|
await this.store.order.recalculateSummary({
|
|
2450
2613
|
createIfMissing: true
|
|
@@ -4106,35 +4269,40 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4106
4269
|
transformBaseProductToOrderProduct(params) {
|
|
4107
4270
|
return (0, _transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
|
|
4108
4271
|
}
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4272
|
+
|
|
4273
|
+
/** Explicit pool source avoids races between two simultaneous Venue pricing contexts. */
|
|
4274
|
+
async calculateVenueCatalogProductBookingPrice(params, source) {
|
|
4112
4275
|
const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
|
|
4113
4276
|
await this.prepareProductPriceQueryContext(customerId);
|
|
4114
4277
|
const channel = this.getPriceQueryChannel(params.channel);
|
|
4115
|
-
const
|
|
4116
|
-
|
|
4278
|
+
const queryPayload = this.buildPriceQueryPayload({
|
|
4279
|
+
ids: [Number(source.product.id)],
|
|
4117
4280
|
schedule: this.getPriceQuerySchedule(params),
|
|
4118
4281
|
customerId,
|
|
4119
4282
|
channel
|
|
4120
4283
|
});
|
|
4121
|
-
const
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4284
|
+
const authoritativeProduct = this.resolveLocalProductForPriceQuery({
|
|
4285
|
+
selectedProduct: params.product,
|
|
4286
|
+
rawProduct: source.product,
|
|
4287
|
+
menuList: source.menuList,
|
|
4288
|
+
queryPayload
|
|
4289
|
+
});
|
|
4290
|
+
if (!authoritativeProduct) throw Object.assign(new Error('Complete product pricing rules are not ready. Please retry.'), {
|
|
4291
|
+
code: 'VENUE_LOCAL_PRICE_UNAVAILABLE'
|
|
4292
|
+
});
|
|
4129
4293
|
return (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
4130
4294
|
...params,
|
|
4131
4295
|
channel,
|
|
4132
|
-
product,
|
|
4133
|
-
fallback_price: authoritativeProduct ? undefined : params.fallback_price,
|
|
4134
4296
|
customer_id: customerId,
|
|
4135
|
-
|
|
4297
|
+
product: this.mergeProductForPriceQuery(params.product, authoritativeProduct),
|
|
4298
|
+
fallback_price: undefined,
|
|
4299
|
+
quotation: undefined
|
|
4136
4300
|
});
|
|
4137
4301
|
}
|
|
4302
|
+
async calculateProductBookingPrice(params) {
|
|
4303
|
+
const [result] = await this.calculateProductBookingPrices([params]);
|
|
4304
|
+
return result;
|
|
4305
|
+
}
|
|
4138
4306
|
getQuotationCustomerScopeInfo() {
|
|
4139
4307
|
const quotation = this.store.quotation;
|
|
4140
4308
|
if (quotation && typeof quotation.getQuotationCustomerScopeInfo === 'function') {
|
|
@@ -4197,11 +4365,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4197
4365
|
}
|
|
4198
4366
|
return shouldRecalculate;
|
|
4199
4367
|
}
|
|
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();
|
|
4368
|
+
async resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId, strictDurationPricing = false) {
|
|
4205
4369
|
const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
|
|
4206
4370
|
const authoritativeProducts = paramsList.map(() => null);
|
|
4207
4371
|
const groups = new Map();
|
|
@@ -4219,22 +4383,68 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4219
4383
|
group.indices.push(index);
|
|
4220
4384
|
groups.set(groupKey, group);
|
|
4221
4385
|
});
|
|
4222
|
-
await
|
|
4386
|
+
await (0, _posDurationPricing.forEachPriceQueryGroup)(Array.from(groups.values()), async group => {
|
|
4223
4387
|
await this.prepareProductPriceQueryContext(group.customerId);
|
|
4224
4388
|
const priceQueries = group.indices.map(index => paramsList[index]);
|
|
4225
4389
|
const resolvedProducts = await this.resolveProductsForPriceQuery({
|
|
4226
4390
|
priceQueries,
|
|
4227
4391
|
schedule: group.schedule,
|
|
4228
4392
|
customerId: group.customerId,
|
|
4229
|
-
channel: group.channel
|
|
4393
|
+
channel: group.channel,
|
|
4394
|
+
strictDurationPricing
|
|
4230
4395
|
});
|
|
4231
4396
|
group.indices.forEach((originalIndex, groupIndex) => {
|
|
4232
4397
|
authoritativeProducts[originalIndex] = resolvedProducts[groupIndex] || null;
|
|
4233
4398
|
});
|
|
4234
|
-
}));
|
|
4399
|
+
}, (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos' ? 4 : groups.size);
|
|
4400
|
+
return authoritativeProducts;
|
|
4401
|
+
}
|
|
4402
|
+
async calculateProductBookingPrices(paramsList) {
|
|
4403
|
+
if (!paramsList.length) return [];
|
|
4404
|
+
const useCustomerUserPricing = this.isCustomerUserPriceQuery();
|
|
4405
|
+
const isPos = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos';
|
|
4406
|
+
const quotation = useCustomerUserPricing ? undefined : this.store.quotation;
|
|
4407
|
+
const currentOrderCustomerId = this.getCurrentOrderCustomerId();
|
|
4408
|
+
const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
|
|
4409
|
+
const authoritativeProducts = await this.resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId);
|
|
4410
|
+
const plans = paramsList.map((params, index) => {
|
|
4411
|
+
if (!isPos) return null;
|
|
4412
|
+
const product = authoritativeProducts[index];
|
|
4413
|
+
if (!product && ((0, _posDurationPricing.usesPosDurationPricing)(params.product) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(params.product))) {
|
|
4414
|
+
throw (0, _posDurationPricing.durationPricingUnavailable)('The authoritative product is unavailable for duration pricing.');
|
|
4415
|
+
}
|
|
4416
|
+
// Read configuration from the response itself: an omitted field must not inherit an old snapshot.
|
|
4417
|
+
return product && (0, _posDurationPricing.usesPosDurationPricing)(product) ? (0, _posDurationPricing.buildPosDurationPricingPlan)(params, product) : null;
|
|
4418
|
+
});
|
|
4419
|
+
const segmentQueries = [];
|
|
4420
|
+
const segmentQueryIndices = plans.map((plan, index) => plan?.segments.slice(1).map(segment => {
|
|
4421
|
+
const queryIndex = segmentQueries.length;
|
|
4422
|
+
segmentQueries.push({
|
|
4423
|
+
...paramsList[index],
|
|
4424
|
+
product: {
|
|
4425
|
+
...paramsList[index].product,
|
|
4426
|
+
product_bundle: undefined
|
|
4427
|
+
},
|
|
4428
|
+
booking: {
|
|
4429
|
+
...paramsList[index].booking,
|
|
4430
|
+
start_date: segment.start.slice(0, 10),
|
|
4431
|
+
start_time: segment.start.slice(11),
|
|
4432
|
+
end_date: segment.end.slice(0, 10),
|
|
4433
|
+
end_time: segment.end.slice(11)
|
|
4434
|
+
},
|
|
4435
|
+
duration: undefined,
|
|
4436
|
+
fallback_price: undefined
|
|
4437
|
+
});
|
|
4438
|
+
return queryIndex;
|
|
4439
|
+
}) || []);
|
|
4440
|
+
const segmentProducts = await this.resolveProductBookingPriceGroups(segmentQueries, currentOrderCustomerId, true);
|
|
4441
|
+
if (segmentProducts.some(product => !product)) {
|
|
4442
|
+
throw (0, _posDurationPricing.durationPricingUnavailable)('An authoritative product is missing for a billing unit.');
|
|
4443
|
+
}
|
|
4235
4444
|
if (!useCustomerUserPricing) {
|
|
4236
4445
|
const quotationContexts = new Map();
|
|
4237
4446
|
paramsList.forEach((params, index) => {
|
|
4447
|
+
if (plans[index]) return;
|
|
4238
4448
|
const channel = resolvedChannels[index];
|
|
4239
4449
|
const key = channel || '';
|
|
4240
4450
|
if (quotationContexts.has(key)) return;
|
|
@@ -4254,16 +4464,59 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4254
4464
|
const product = this.mergeProductForPriceQuery(productInput, authoritativeProduct);
|
|
4255
4465
|
const customerId = params.customer_id ?? currentOrderCustomerId;
|
|
4256
4466
|
const channel = resolvedChannels[index];
|
|
4257
|
-
|
|
4467
|
+
const plan = plans[index];
|
|
4468
|
+
if (plan) {
|
|
4469
|
+
const unitProducts = [authoritativeProduct, ...segmentQueryIndices[index].map(queryIndex => segmentProducts[queryIndex])];
|
|
4470
|
+
const prices = unitProducts.map((unitProduct, unitIndex) => (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
4471
|
+
...params,
|
|
4472
|
+
channel,
|
|
4473
|
+
product: this.mergeProductForPriceQuery(unitIndex === 0 ? productInput : {
|
|
4474
|
+
...productInput,
|
|
4475
|
+
product_bundle: undefined
|
|
4476
|
+
}, unitProduct),
|
|
4477
|
+
booking: {
|
|
4478
|
+
...params.booking,
|
|
4479
|
+
start_date: plan.segments[unitIndex].start.slice(0, 10),
|
|
4480
|
+
start_time: plan.segments[unitIndex].start.slice(11)
|
|
4481
|
+
},
|
|
4482
|
+
duration: undefined,
|
|
4483
|
+
fallback_price: undefined,
|
|
4484
|
+
customer_id: customerId,
|
|
4485
|
+
quotation: undefined
|
|
4486
|
+
}));
|
|
4487
|
+
return (0, _posDurationPricing.combinePosDurationPrices)(plan, prices);
|
|
4488
|
+
}
|
|
4489
|
+
const changedToFixed = isPos && ((0, _posDurationPricing.usesPosDurationPricing)(productInput) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(productInput)) && authoritativeProduct && !(0, _posDurationPricing.usesPosDurationPricing)(authoritativeProduct);
|
|
4490
|
+
// A switch to Days can explicitly request the existing per-day quotation path.
|
|
4491
|
+
// Discard the old minute basis, but do not erase that independent legacy input.
|
|
4492
|
+
const keepLegacyDayDuration = changedToFixed && ['day', 'days'].includes(String(authoritativeProduct?.duration?.type || '').trim().toLowerCase()) && ['day', 'days'].includes(String(params.duration?.type || '').trim().toLowerCase());
|
|
4493
|
+
const result = (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
4258
4494
|
...params,
|
|
4495
|
+
...(changedToFixed && !keepLegacyDayDuration ? {
|
|
4496
|
+
duration: undefined
|
|
4497
|
+
} : {}),
|
|
4259
4498
|
channel,
|
|
4260
4499
|
product,
|
|
4261
4500
|
fallback_price: authoritativeProduct ? undefined : params.fallback_price,
|
|
4262
4501
|
customer_id: customerId,
|
|
4263
4502
|
quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? undefined : quotation
|
|
4264
4503
|
});
|
|
4504
|
+
return changedToFixed ? {
|
|
4505
|
+
...result,
|
|
4506
|
+
pricing_method: {
|
|
4507
|
+
type: 'fixed_price'
|
|
4508
|
+
},
|
|
4509
|
+
duration: undefined
|
|
4510
|
+
} : result;
|
|
4265
4511
|
});
|
|
4266
4512
|
}
|
|
4513
|
+
setProductVoucherGroups(groups) {
|
|
4514
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
4515
|
+
this.store.order.setProductVoucherGroups(groups);
|
|
4516
|
+
}
|
|
4517
|
+
validateProductVoucherSelection() {
|
|
4518
|
+
this.store.order?.validateProductVoucherSelection();
|
|
4519
|
+
}
|
|
4267
4520
|
async addProductToOrder(product, booking, options) {
|
|
4268
4521
|
try {
|
|
4269
4522
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
@@ -4293,10 +4546,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4293
4546
|
throw error;
|
|
4294
4547
|
}
|
|
4295
4548
|
}
|
|
4296
|
-
async updateOrderProducts(paramsList) {
|
|
4549
|
+
async updateOrderProducts(paramsList, options) {
|
|
4297
4550
|
try {
|
|
4298
4551
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
4299
|
-
const products = await this.store.order.updateOrderProducts(paramsList);
|
|
4552
|
+
const products = await this.store.order.updateOrderProducts(paramsList, options);
|
|
4300
4553
|
return products;
|
|
4301
4554
|
} catch (error) {
|
|
4302
4555
|
throw error;
|
|
@@ -13,6 +13,7 @@ import type { SubmitPayloadEnhancer } from '../../modules/Order/utils';
|
|
|
13
13
|
export declare const BaseSalesHookNames: {
|
|
14
14
|
readonly onInited: "onInited";
|
|
15
15
|
readonly onDestroy: "onDestroy";
|
|
16
|
+
readonly onOrderSessionChanged: "onOrderSessionChanged";
|
|
16
17
|
readonly onRetryInit: "onRetryInit";
|
|
17
18
|
readonly onRefresh: "onRefresh";
|
|
18
19
|
readonly onCartValidationChanged: "onCartValidationChanged";
|
|
@@ -348,6 +349,9 @@ export interface BaseSalesProductBookingPriceResult {
|
|
|
348
349
|
unit_price: string;
|
|
349
350
|
total_price: string;
|
|
350
351
|
quantity: number;
|
|
352
|
+
pricing_method?: {
|
|
353
|
+
type: 'fixed_price' | 'duration_based';
|
|
354
|
+
};
|
|
351
355
|
duration?: BaseSalesQuotationDurationConfig;
|
|
352
356
|
quotation_shelf_id: number;
|
|
353
357
|
segments: BaseSalesProductBookingPriceSegment[];
|
|
@@ -12,6 +12,7 @@ exports.createBaseSalesHook = createBaseSalesHook;
|
|
|
12
12
|
const BaseSalesHookNames = exports.BaseSalesHookNames = {
|
|
13
13
|
onInited: 'onInited',
|
|
14
14
|
onDestroy: 'onDestroy',
|
|
15
|
+
onOrderSessionChanged: 'onOrderSessionChanged',
|
|
15
16
|
onRetryInit: 'onRetryInit',
|
|
16
17
|
onRefresh: 'onRefresh',
|
|
17
18
|
onCartValidationChanged: 'onCartValidationChanged',
|
|
@@ -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>;
|