@pisell/pisellos 2.3.184 → 2.3.186
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/Discount/index.js +1 -0
- package/dist/modules/Order/index.d.ts +25 -3
- package/dist/modules/Order/index.js +1770 -1311
- package/dist/modules/Order/types.d.ts +7 -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.js +12 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/types.d.ts +5 -0
- package/dist/modules/ProductList/index.js +33 -12
- package/dist/modules/Rules/index.d.ts +2 -0
- package/dist/modules/Rules/index.js +29 -21
- package/dist/solution/BaseSales/index.d.ts +18 -1
- package/dist/solution/BaseSales/index.js +1762 -1434
- 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 +2 -2
- package/dist/solution/BookingTicket/index.d.ts +13 -1
- package/dist/solution/BookingTicket/index.js +197 -108
- package/dist/solution/BookingTicket/types.d.ts +14 -2
- package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
- package/dist/solution/BookingTicket/utils/addProductDecision.js +4 -3
- 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/UnifiedBookingSales/index.d.ts +1 -1
- package/dist/solution/UnifiedBookingSales/index.js +102 -64
- package/dist/utils/platform.d.ts +2 -0
- package/dist/utils/platform.js +6 -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/modules/Discount/index.js +1 -0
- package/lib/modules/Order/index.d.ts +25 -3
- package/lib/modules/Order/index.js +192 -38
- package/lib/modules/Order/types.d.ts +7 -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.js +13 -0
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/types.d.ts +5 -0
- package/lib/modules/ProductList/index.js +15 -0
- package/lib/modules/Rules/index.d.ts +2 -0
- package/lib/modules/Rules/index.js +6 -0
- package/lib/solution/BaseSales/index.d.ts +18 -1
- package/lib/solution/BaseSales/index.js +214 -50
- 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 +2 -2
- package/lib/solution/BookingTicket/index.d.ts +13 -1
- package/lib/solution/BookingTicket/index.js +37 -2
- package/lib/solution/BookingTicket/types.d.ts +14 -2
- package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +1 -1
- package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -3
- 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/UnifiedBookingSales/index.d.ts +1 -1
- package/lib/solution/UnifiedBookingSales/index.js +37 -4
- package/lib/utils/platform.d.ts +2 -0
- package/lib/utils/platform.js +7 -0
- package/package.json +1 -1
|
@@ -9,6 +9,8 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
|
|
|
9
9
|
private store;
|
|
10
10
|
window: WindowPlugin;
|
|
11
11
|
private hooks;
|
|
12
|
+
private discountScope?;
|
|
13
|
+
setDiscountScope(scope: (product: any, discount: Discount) => boolean): void;
|
|
12
14
|
constructor(name?: string, version?: string);
|
|
13
15
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
14
16
|
setRulesList(rulesList: Rules[]): Promise<void>;
|
|
@@ -22,6 +22,10 @@ class RulesModule extends _BaseModule.BaseModule {
|
|
|
22
22
|
store;
|
|
23
23
|
window; // WindowPlugin 实例
|
|
24
24
|
hooks;
|
|
25
|
+
discountScope;
|
|
26
|
+
setDiscountScope(scope) {
|
|
27
|
+
this.discountScope = scope;
|
|
28
|
+
}
|
|
25
29
|
constructor(name, version) {
|
|
26
30
|
super(name, version);
|
|
27
31
|
this.hooks = {};
|
|
@@ -745,6 +749,7 @@ class RulesModule extends _BaseModule.BaseModule {
|
|
|
745
749
|
|
|
746
750
|
// 辅助函数:检查商品是否对某个折扣卡可用
|
|
747
751
|
const checkItemApplicableForDiscount = (flatItem, discount) => {
|
|
752
|
+
if (this.discountScope && !this.discountScope(flatItem.originProduct, discount)) return false;
|
|
748
753
|
if (discount.config?.isAvailable === false) return false;
|
|
749
754
|
if (isCardBlockedByPromotion(flatItem, discount)) return false;
|
|
750
755
|
let product;
|
|
@@ -1156,6 +1161,7 @@ class RulesModule extends _BaseModule.BaseModule {
|
|
|
1156
1161
|
|
|
1157
1162
|
// 找到适用于此商品的所有优惠券,仅考虑isSelected不为false的优惠券
|
|
1158
1163
|
const applicableDiscounts = sortedDiscountList.filter(discount => {
|
|
1164
|
+
if (this.discountScope && !this.discountScope(originProduct, discount)) return false;
|
|
1159
1165
|
if (this.isItemRewardProductDiscount(product)) return false;
|
|
1160
1166
|
if (isCardBlockedByPromotion(flatItem, discount)) return false;
|
|
1161
1167
|
// 🔥 检查策略可用性(针对全额抵扣卡和折扣卡)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InventoryController, type CheckoutRuntimeSnapshot } from '../../inventory';
|
|
1
2
|
import { Module, ModuleOptions, PisellCore } from '../../types';
|
|
2
3
|
import { BaseModule } from '../../modules/BaseModule';
|
|
3
4
|
import { type LocalEftposFinalization } from '../../modules/Order/localEftposState';
|
|
@@ -52,6 +53,8 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
52
53
|
protected appPlugin: AppPlugin;
|
|
53
54
|
protected store: BaseSalesState;
|
|
54
55
|
protected otherParams: Record<string, any>;
|
|
56
|
+
getInventory(): InventoryController | undefined;
|
|
57
|
+
prepareCheckout(signal?: AbortSignal): Promise<CheckoutRuntimeSnapshot | undefined>;
|
|
55
58
|
protected cacheId: string | undefined;
|
|
56
59
|
/**
|
|
57
60
|
* 由已在初始化阶段解析过设备短号的业务解决方案写入。
|
|
@@ -66,6 +69,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
66
69
|
request: RequestPlugin;
|
|
67
70
|
protected currentSalesDetail: ISalesDetail | null;
|
|
68
71
|
protected discountConfigCacheKey: string | null;
|
|
72
|
+
private discountConfigPrepareInFlight;
|
|
69
73
|
protected hasManualDiscountSelection: boolean;
|
|
70
74
|
private readonly reusedSharedSubModuleNames;
|
|
71
75
|
private paymentMethodsCache;
|
|
@@ -194,6 +198,7 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
194
198
|
* 可覆盖此方法并把未识别的 name 委托给 `super.createSubModule(name)`。
|
|
195
199
|
*/
|
|
196
200
|
protected createSubModule(moduleName: string): Module | null;
|
|
201
|
+
private inventoryOrderHooks?;
|
|
197
202
|
protected getSubModuleHooks(moduleName: string): any;
|
|
198
203
|
/**
|
|
199
204
|
* 构造传给 BaseSales 子模块的完整运行态参数,保证初始化和后续同步语义一致。
|
|
@@ -231,7 +236,11 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
231
236
|
private isActiveVirtualSettlementOrder;
|
|
232
237
|
private isHistoricalVirtualSettlementOrder;
|
|
233
238
|
private syncAppDataToTempOrder;
|
|
239
|
+
private initialization?;
|
|
240
|
+
/** Hosts can await readiness without changing Core's synchronous registration API. */
|
|
241
|
+
whenInitialized(): Promise<void>;
|
|
234
242
|
initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
|
|
243
|
+
private initializeSalesRuntime;
|
|
235
244
|
destroy(): Promise<void>;
|
|
236
245
|
/**
|
|
237
246
|
* 加载销售订单到统一 tempOrder 工作区。
|
|
@@ -340,7 +349,9 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
340
349
|
discountList: Discount[];
|
|
341
350
|
originalDiscountList?: Discount[];
|
|
342
351
|
}): Promise<void>;
|
|
343
|
-
scanPromotionCode(code: string, customerId?: number
|
|
352
|
+
scanPromotionCode(code: string, customerId?: number, options?: {
|
|
353
|
+
productVouchersOnly?: boolean;
|
|
354
|
+
}): Promise<BaseSalesScanCodeResult>;
|
|
344
355
|
setDiscountSelected(params: {
|
|
345
356
|
discountId: number;
|
|
346
357
|
isSelected: boolean;
|
|
@@ -524,7 +535,13 @@ export declare class BaseSalesImpl extends BaseModule implements Module {
|
|
|
524
535
|
getQuotationCustomerScopeInfo(): BaseSalesQuotationCustomerScopeInfo;
|
|
525
536
|
private hasSmartPricingStrategies;
|
|
526
537
|
shouldRecalculateProductBookingPricesForContextChange(params: BaseSalesPriceRecalculationContextChange): boolean;
|
|
538
|
+
private resolveProductBookingPriceGroups;
|
|
527
539
|
calculateProductBookingPrices(paramsList: BaseSalesCalculateProductBookingPriceParams[]): Promise<BaseSalesProductBookingPriceResult[]>;
|
|
540
|
+
setProductVoucherGroups(groups: Array<{
|
|
541
|
+
key: string;
|
|
542
|
+
discountIds: Array<number | string>;
|
|
543
|
+
}>): void;
|
|
544
|
+
validateProductVoucherSelection(): void;
|
|
528
545
|
addProductToOrder(product: Partial<BaseSalesOrderProduct> & BaseSalesOrderProductIdentity, booking?: AddProductBookingInput, options?: AddProductToOrderOptions): Promise<import("../../modules/Order/types").OrderProduct[]>;
|
|
529
546
|
updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
|
|
530
547
|
updateOrderProducts(paramsList: UpdateOrderProductParams[]): Promise<import("../../modules/Order/types").OrderProduct[]>;
|
|
@@ -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");
|
|
@@ -42,6 +43,7 @@ var _platform = require("../../utils/platform");
|
|
|
42
43
|
var _Quotation = require("../../modules/Quotation");
|
|
43
44
|
var _transformBaseProductToOrderProduct = require("./utils/transformBaseProductToOrderProduct");
|
|
44
45
|
var _quotationPrice = require("./utils/quotationPrice");
|
|
46
|
+
var _posDurationPricing = require("./utils/posDurationPricing");
|
|
45
47
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
46
48
|
const SERVER_ORDER_CHANGED_EVENT = 'order:onOrdersChanged';
|
|
47
49
|
const PAYMENT_METHODS_CHANGED_EVENT = 'payment:onPaymentMethodsChanged';
|
|
@@ -511,6 +513,40 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
511
513
|
order: undefined
|
|
512
514
|
};
|
|
513
515
|
otherParams = {};
|
|
516
|
+
getInventory() {
|
|
517
|
+
return this.otherParams.inventory;
|
|
518
|
+
}
|
|
519
|
+
async prepareCheckout(signal) {
|
|
520
|
+
const inventory = this.getInventory();
|
|
521
|
+
const hooks = this.otherParams.checkoutHooks;
|
|
522
|
+
if (!inventory && !hooks?.beforeCheckout) return undefined;
|
|
523
|
+
if (!this.store.order) throw new Error('Order module is not ready');
|
|
524
|
+
return this.store.order.prepareCheckout(async items => {
|
|
525
|
+
const assertCurrent = () => {
|
|
526
|
+
if (signal?.aborted) throw Object.assign(new Error('Checkout cancelled'), {
|
|
527
|
+
name: 'AbortError'
|
|
528
|
+
});
|
|
529
|
+
if (inventory !== this.getInventory() || hooks !== this.otherParams.checkoutHooks) throw (0, _inventory.salesGuardError)('The sales context changed. Please try again.');
|
|
530
|
+
};
|
|
531
|
+
assertCurrent();
|
|
532
|
+
try {
|
|
533
|
+
await hooks?.beforeCheckout?.({
|
|
534
|
+
items,
|
|
535
|
+
signal
|
|
536
|
+
});
|
|
537
|
+
if (inventory) await inventory.refresh({
|
|
538
|
+
reason: 'checkout',
|
|
539
|
+
force: true,
|
|
540
|
+
signal
|
|
541
|
+
});
|
|
542
|
+
assertCurrent();
|
|
543
|
+
return inventory?.freezeCheckout(items);
|
|
544
|
+
} catch (error) {
|
|
545
|
+
if (error?.name === 'AbortError') throw error;
|
|
546
|
+
throw (0, _inventory.salesGuardError)(error instanceof Error ? error.message : String(error));
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
}
|
|
514
550
|
cacheId;
|
|
515
551
|
/**
|
|
516
552
|
* 由已在初始化阶段解析过设备短号的业务解决方案写入。
|
|
@@ -527,6 +563,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
527
563
|
// 当前缓存中已加载的最新 SalesDetail;只读 getter 走它对外暴露详情数据。
|
|
528
564
|
currentSalesDetail = null;
|
|
529
565
|
discountConfigCacheKey = null;
|
|
566
|
+
discountConfigPrepareInFlight = null;
|
|
530
567
|
hasManualDiscountSelection = false;
|
|
531
568
|
reusedSharedSubModuleNames = new Set();
|
|
532
569
|
paymentMethodsCache = [];
|
|
@@ -1091,6 +1128,9 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1091
1128
|
const shouldAlignSelectedVariantPrice = handledByOsServer && this.preferAuthoritativeProductQueryPrice();
|
|
1092
1129
|
return productIds.map((productId, index) => {
|
|
1093
1130
|
const authoritativeProduct = productId === null ? null : productsById.get(productId) || null;
|
|
1131
|
+
if (authoritativeProduct && (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos' && (params.strictDurationPricing || (0, _posDurationPricing.usesPosDurationPricing)(authoritativeProduct) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(selectedProducts[index]))) {
|
|
1132
|
+
return (0, _posDurationPricing.resolveDurationPricingProduct)(authoritativeProduct, selectedProducts[index]);
|
|
1133
|
+
}
|
|
1094
1134
|
if (!shouldAlignSelectedVariantPrice || !authoritativeProduct) return authoritativeProduct;
|
|
1095
1135
|
const selectedProduct = selectedProducts[index];
|
|
1096
1136
|
const selectedVariantId = this.getSelectedProductVariantId(selectedProduct);
|
|
@@ -1208,6 +1248,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1208
1248
|
return {
|
|
1209
1249
|
...product,
|
|
1210
1250
|
...authoritativeProduct,
|
|
1251
|
+
// An omitted current configuration clears a previous catalog/order snapshot.
|
|
1252
|
+
pricing_method: authoritativeProduct.pricing_method,
|
|
1211
1253
|
id: product.id ?? authoritativeProduct.id,
|
|
1212
1254
|
product_id: product.product_id ?? authoritativeProduct.product_id ?? authoritativeProduct.id,
|
|
1213
1255
|
product_variant_id: product.product_variant_id ?? authoritativeProduct.product_variant_id ?? 0,
|
|
@@ -1401,12 +1443,35 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1401
1443
|
}
|
|
1402
1444
|
return (0, _types2.createModule)(moduleName, this.name);
|
|
1403
1445
|
}
|
|
1446
|
+
inventoryOrderHooks;
|
|
1404
1447
|
getSubModuleHooks(moduleName) {
|
|
1405
1448
|
const optionHooks = this.initializeOptions.hooks || {};
|
|
1406
1449
|
const otherHooks = this.otherParams.hooks || {};
|
|
1407
1450
|
if (moduleName === 'order') {
|
|
1408
1451
|
const directOrderHooks = optionHooks;
|
|
1409
|
-
|
|
1452
|
+
const hooks = optionHooks.order || this.otherParams.order?.hooks || otherHooks.order || (directOrderHooks.onBeforeMergeProductToOrder || directOrderHooks.onBeforeCartCommit ? directOrderHooks : undefined);
|
|
1453
|
+
const inventory = this.getInventory();
|
|
1454
|
+
if (!inventory) {
|
|
1455
|
+
this.inventoryOrderHooks = undefined;
|
|
1456
|
+
return hooks;
|
|
1457
|
+
}
|
|
1458
|
+
if (this.inventoryOrderHooks?.inventory === inventory && this.inventoryOrderHooks.base === hooks) {
|
|
1459
|
+
return this.inventoryOrderHooks.hooks;
|
|
1460
|
+
}
|
|
1461
|
+
const combined = {
|
|
1462
|
+
...hooks,
|
|
1463
|
+
onBeforeCartCommit: async context => {
|
|
1464
|
+
await hooks?.onBeforeCartCommit?.(context);
|
|
1465
|
+
if (inventory !== this.getInventory()) throw (0, _inventory.salesGuardError)('The sales context changed. Please try again.');
|
|
1466
|
+
inventory.validate(context.proposedItems, context.currentItems);
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
this.inventoryOrderHooks = {
|
|
1470
|
+
inventory,
|
|
1471
|
+
base: hooks,
|
|
1472
|
+
hooks: combined
|
|
1473
|
+
};
|
|
1474
|
+
return combined;
|
|
1410
1475
|
}
|
|
1411
1476
|
return optionHooks[moduleName] || this.otherParams[moduleName]?.hooks || otherHooks[moduleName];
|
|
1412
1477
|
}
|
|
@@ -1454,7 +1519,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1454
1519
|
const nextSubModuleOtherParams = this.buildSubModuleOtherParams(moduleName);
|
|
1455
1520
|
await targetModule.updateOtherParams(nextSubModuleOtherParams, {
|
|
1456
1521
|
changedParams,
|
|
1457
|
-
cover
|
|
1522
|
+
cover,
|
|
1523
|
+
...(moduleName === 'order' ? {
|
|
1524
|
+
hooks: this.getSubModuleHooks(moduleName)
|
|
1525
|
+
} : {})
|
|
1458
1526
|
});
|
|
1459
1527
|
}));
|
|
1460
1528
|
}
|
|
@@ -1603,7 +1671,17 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1603
1671
|
}
|
|
1604
1672
|
return isChanged;
|
|
1605
1673
|
}
|
|
1606
|
-
|
|
1674
|
+
initialization;
|
|
1675
|
+
|
|
1676
|
+
/** Hosts can await readiness without changing Core's synchronous registration API. */
|
|
1677
|
+
whenInitialized() {
|
|
1678
|
+
return this.initialization || Promise.reject(new Error('Sales module is not registered'));
|
|
1679
|
+
}
|
|
1680
|
+
initialize(core, options = {}) {
|
|
1681
|
+
this.initialization = this.initializeSalesRuntime(core, options);
|
|
1682
|
+
return this.initialization;
|
|
1683
|
+
}
|
|
1684
|
+
async initializeSalesRuntime(core, options = {}) {
|
|
1607
1685
|
this.resetPickupTimingCache();
|
|
1608
1686
|
this.core = core;
|
|
1609
1687
|
this.initializeOptions = options || {};
|
|
@@ -1663,17 +1741,19 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
1663
1741
|
this.serverOrderChangeUnsubscribe = null;
|
|
1664
1742
|
this.paymentMethodsChangedUnsubscribe?.();
|
|
1665
1743
|
this.paymentMethodsChangedUnsubscribe = null;
|
|
1666
|
-
Object.keys(this.store)
|
|
1667
|
-
if (this.reusedSharedSubModuleNames.has(key))
|
|
1744
|
+
for (const key of Object.keys(this.store)) {
|
|
1745
|
+
if (this.reusedSharedSubModuleNames.has(key)) continue;
|
|
1668
1746
|
const sub = this.store[key];
|
|
1669
1747
|
if (sub && typeof sub.destroy === 'function') {
|
|
1670
1748
|
try {
|
|
1671
|
-
|
|
1749
|
+
// A host may register a replacement after destroy resolves. Wait for
|
|
1750
|
+
// nested modules so their cleanup cannot unregister the replacement.
|
|
1751
|
+
await sub.destroy();
|
|
1672
1752
|
} catch (error) {
|
|
1673
1753
|
console.warn(`[BaseSales] 子模块 ${key} 销毁失败`, error);
|
|
1674
1754
|
}
|
|
1675
1755
|
}
|
|
1676
|
-
}
|
|
1756
|
+
}
|
|
1677
1757
|
this.currentSalesDetail = null;
|
|
1678
1758
|
this.paymentNumberDevicePrefix = null;
|
|
1679
1759
|
this.queuedServerOrderChanges = [];
|
|
@@ -2210,9 +2290,16 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2210
2290
|
const searchedDiscountIds = new Set(searchedDiscountList.map(discount => String(discount.id)));
|
|
2211
2291
|
let preparedDiscountList = [...searchedDiscountList, ...originalDiscountList.filter(discount => !searchedDiscountIds.has(String(discount.id)))];
|
|
2212
2292
|
if (customerId && customerId !== 1) {
|
|
2213
|
-
|
|
2293
|
+
const inFlight = this.discountConfigPrepareInFlight;
|
|
2294
|
+
// 客户刷新和商品查询共享配置准备;force 仅绕过已完成的缓存。
|
|
2295
|
+
if (inFlight?.key === discountConfigCacheKey && inFlight.epoch === requestEpoch) {
|
|
2296
|
+
preparedDiscountList = await inFlight.promise;
|
|
2297
|
+
if (!isCurrentRequest()) return getCurrentResult();
|
|
2298
|
+
} else if (!params?.force && this.discountConfigCacheKey === discountConfigCacheKey) {
|
|
2214
2299
|
preparedDiscountList = originalDiscountList;
|
|
2215
2300
|
} else {
|
|
2301
|
+
// 强制刷新失败后,下次普通加载也应重试,不能命中刷新前的缓存。
|
|
2302
|
+
this.discountConfigCacheKey = null;
|
|
2216
2303
|
const prepareConfigPromise = this.store.order.loadDiscountConfig({
|
|
2217
2304
|
customerId,
|
|
2218
2305
|
action: discountAction,
|
|
@@ -2221,11 +2308,28 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2221
2308
|
});
|
|
2222
2309
|
// OrderModule increments this epoch synchronously before its first await.
|
|
2223
2310
|
requestEpoch = this.store.order.getCustomerWalletPrepareConfigEpoch?.();
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2311
|
+
const prepareTask = {
|
|
2312
|
+
key: discountConfigCacheKey,
|
|
2313
|
+
epoch: requestEpoch,
|
|
2314
|
+
promise: prepareConfigPromise.then(async discountList => {
|
|
2315
|
+
if (!isCurrentRequest()) return discountList;
|
|
2316
|
+
await discountModule?.setOriginalDiscountList?.(discountList);
|
|
2317
|
+
if (isCurrentRequest()) {
|
|
2318
|
+
this.discountConfigCacheKey = discountConfigCacheKey;
|
|
2319
|
+
}
|
|
2320
|
+
return discountList;
|
|
2321
|
+
})
|
|
2322
|
+
};
|
|
2323
|
+
this.discountConfigPrepareInFlight = prepareTask;
|
|
2324
|
+
try {
|
|
2325
|
+
preparedDiscountList = await prepareTask.promise;
|
|
2326
|
+
} finally {
|
|
2327
|
+
// 旧请求结束时不能清掉客户/订单切换后创建的新任务。
|
|
2328
|
+
if (this.discountConfigPrepareInFlight === prepareTask) {
|
|
2329
|
+
this.discountConfigPrepareInFlight = null;
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2227
2332
|
if (!isCurrentRequest()) return getCurrentResult();
|
|
2228
|
-
this.discountConfigCacheKey = discountConfigCacheKey;
|
|
2229
2333
|
}
|
|
2230
2334
|
}
|
|
2231
2335
|
if (this.isActiveVirtualSettlementOrder(tempOrder)) {
|
|
@@ -2441,10 +2545,10 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
2441
2545
|
}
|
|
2442
2546
|
await discountModule.setDiscountList(params.discountList);
|
|
2443
2547
|
}
|
|
2444
|
-
async scanPromotionCode(code, customerId) {
|
|
2548
|
+
async scanPromotionCode(code, customerId, options) {
|
|
2445
2549
|
try {
|
|
2446
2550
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
2447
|
-
const raw = await this.store.order.scanCode(code, customerId);
|
|
2551
|
+
const raw = await this.store.order.scanCode(code, customerId, options);
|
|
2448
2552
|
if (raw.isAvailable) {
|
|
2449
2553
|
await this.store.order.recalculateSummary({
|
|
2450
2554
|
createIfMissing: true
|
|
@@ -4107,33 +4211,8 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4107
4211
|
return (0, _transformBaseProductToOrderProduct.transformBaseProductToOrderProduct)(params);
|
|
4108
4212
|
}
|
|
4109
4213
|
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
|
-
});
|
|
4214
|
+
const [result] = await this.calculateProductBookingPrices([params]);
|
|
4215
|
+
return result;
|
|
4137
4216
|
}
|
|
4138
4217
|
getQuotationCustomerScopeInfo() {
|
|
4139
4218
|
const quotation = this.store.quotation;
|
|
@@ -4197,11 +4276,7 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4197
4276
|
}
|
|
4198
4277
|
return shouldRecalculate;
|
|
4199
4278
|
}
|
|
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();
|
|
4279
|
+
async resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId, strictDurationPricing = false) {
|
|
4205
4280
|
const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
|
|
4206
4281
|
const authoritativeProducts = paramsList.map(() => null);
|
|
4207
4282
|
const groups = new Map();
|
|
@@ -4219,22 +4294,68 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4219
4294
|
group.indices.push(index);
|
|
4220
4295
|
groups.set(groupKey, group);
|
|
4221
4296
|
});
|
|
4222
|
-
await
|
|
4297
|
+
await (0, _posDurationPricing.forEachPriceQueryGroup)(Array.from(groups.values()), async group => {
|
|
4223
4298
|
await this.prepareProductPriceQueryContext(group.customerId);
|
|
4224
4299
|
const priceQueries = group.indices.map(index => paramsList[index]);
|
|
4225
4300
|
const resolvedProducts = await this.resolveProductsForPriceQuery({
|
|
4226
4301
|
priceQueries,
|
|
4227
4302
|
schedule: group.schedule,
|
|
4228
4303
|
customerId: group.customerId,
|
|
4229
|
-
channel: group.channel
|
|
4304
|
+
channel: group.channel,
|
|
4305
|
+
strictDurationPricing
|
|
4230
4306
|
});
|
|
4231
4307
|
group.indices.forEach((originalIndex, groupIndex) => {
|
|
4232
4308
|
authoritativeProducts[originalIndex] = resolvedProducts[groupIndex] || null;
|
|
4233
4309
|
});
|
|
4234
|
-
}));
|
|
4310
|
+
}, (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos' ? 4 : groups.size);
|
|
4311
|
+
return authoritativeProducts;
|
|
4312
|
+
}
|
|
4313
|
+
async calculateProductBookingPrices(paramsList) {
|
|
4314
|
+
if (!paramsList.length) return [];
|
|
4315
|
+
const useCustomerUserPricing = this.isCustomerUserPriceQuery();
|
|
4316
|
+
const isPos = (0, _platform.normalizeRuntimePlatform)(this.otherParams?.platform) === 'pos';
|
|
4317
|
+
const quotation = useCustomerUserPricing ? undefined : this.store.quotation;
|
|
4318
|
+
const currentOrderCustomerId = this.getCurrentOrderCustomerId();
|
|
4319
|
+
const resolvedChannels = paramsList.map(params => this.getPriceQueryChannel(params.channel));
|
|
4320
|
+
const authoritativeProducts = await this.resolveProductBookingPriceGroups(paramsList, currentOrderCustomerId);
|
|
4321
|
+
const plans = paramsList.map((params, index) => {
|
|
4322
|
+
if (!isPos) return null;
|
|
4323
|
+
const product = authoritativeProducts[index];
|
|
4324
|
+
if (!product && ((0, _posDurationPricing.usesPosDurationPricing)(params.product) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(params.product))) {
|
|
4325
|
+
throw (0, _posDurationPricing.durationPricingUnavailable)('The authoritative product is unavailable for duration pricing.');
|
|
4326
|
+
}
|
|
4327
|
+
// Read configuration from the response itself: an omitted field must not inherit an old snapshot.
|
|
4328
|
+
return product && (0, _posDurationPricing.usesPosDurationPricing)(product) ? (0, _posDurationPricing.buildPosDurationPricingPlan)(params, product) : null;
|
|
4329
|
+
});
|
|
4330
|
+
const segmentQueries = [];
|
|
4331
|
+
const segmentQueryIndices = plans.map((plan, index) => plan?.segments.slice(1).map(segment => {
|
|
4332
|
+
const queryIndex = segmentQueries.length;
|
|
4333
|
+
segmentQueries.push({
|
|
4334
|
+
...paramsList[index],
|
|
4335
|
+
product: {
|
|
4336
|
+
...paramsList[index].product,
|
|
4337
|
+
product_bundle: undefined
|
|
4338
|
+
},
|
|
4339
|
+
booking: {
|
|
4340
|
+
...paramsList[index].booking,
|
|
4341
|
+
start_date: segment.start.slice(0, 10),
|
|
4342
|
+
start_time: segment.start.slice(11),
|
|
4343
|
+
end_date: segment.end.slice(0, 10),
|
|
4344
|
+
end_time: segment.end.slice(11)
|
|
4345
|
+
},
|
|
4346
|
+
duration: undefined,
|
|
4347
|
+
fallback_price: undefined
|
|
4348
|
+
});
|
|
4349
|
+
return queryIndex;
|
|
4350
|
+
}) || []);
|
|
4351
|
+
const segmentProducts = await this.resolveProductBookingPriceGroups(segmentQueries, currentOrderCustomerId, true);
|
|
4352
|
+
if (segmentProducts.some(product => !product)) {
|
|
4353
|
+
throw (0, _posDurationPricing.durationPricingUnavailable)('An authoritative product is missing for a billing unit.');
|
|
4354
|
+
}
|
|
4235
4355
|
if (!useCustomerUserPricing) {
|
|
4236
4356
|
const quotationContexts = new Map();
|
|
4237
4357
|
paramsList.forEach((params, index) => {
|
|
4358
|
+
if (plans[index]) return;
|
|
4238
4359
|
const channel = resolvedChannels[index];
|
|
4239
4360
|
const key = channel || '';
|
|
4240
4361
|
if (quotationContexts.has(key)) return;
|
|
@@ -4254,16 +4375,59 @@ class BaseSalesImpl extends _BaseModule.BaseModule {
|
|
|
4254
4375
|
const product = this.mergeProductForPriceQuery(productInput, authoritativeProduct);
|
|
4255
4376
|
const customerId = params.customer_id ?? currentOrderCustomerId;
|
|
4256
4377
|
const channel = resolvedChannels[index];
|
|
4257
|
-
|
|
4378
|
+
const plan = plans[index];
|
|
4379
|
+
if (plan) {
|
|
4380
|
+
const unitProducts = [authoritativeProduct, ...segmentQueryIndices[index].map(queryIndex => segmentProducts[queryIndex])];
|
|
4381
|
+
const prices = unitProducts.map((unitProduct, unitIndex) => (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
4382
|
+
...params,
|
|
4383
|
+
channel,
|
|
4384
|
+
product: this.mergeProductForPriceQuery(unitIndex === 0 ? productInput : {
|
|
4385
|
+
...productInput,
|
|
4386
|
+
product_bundle: undefined
|
|
4387
|
+
}, unitProduct),
|
|
4388
|
+
booking: {
|
|
4389
|
+
...params.booking,
|
|
4390
|
+
start_date: plan.segments[unitIndex].start.slice(0, 10),
|
|
4391
|
+
start_time: plan.segments[unitIndex].start.slice(11)
|
|
4392
|
+
},
|
|
4393
|
+
duration: undefined,
|
|
4394
|
+
fallback_price: undefined,
|
|
4395
|
+
customer_id: customerId,
|
|
4396
|
+
quotation: undefined
|
|
4397
|
+
}));
|
|
4398
|
+
return (0, _posDurationPricing.combinePosDurationPrices)(plan, prices);
|
|
4399
|
+
}
|
|
4400
|
+
const changedToFixed = isPos && ((0, _posDurationPricing.usesPosDurationPricing)(productInput) || (0, _posDurationPricing.hasAppliedPosDurationPricing)(productInput)) && authoritativeProduct && !(0, _posDurationPricing.usesPosDurationPricing)(authoritativeProduct);
|
|
4401
|
+
// A switch to Days can explicitly request the existing per-day quotation path.
|
|
4402
|
+
// Discard the old minute basis, but do not erase that independent legacy input.
|
|
4403
|
+
const keepLegacyDayDuration = changedToFixed && ['day', 'days'].includes(String(authoritativeProduct?.duration?.type || '').trim().toLowerCase()) && ['day', 'days'].includes(String(params.duration?.type || '').trim().toLowerCase());
|
|
4404
|
+
const result = (0, _quotationPrice.calculateBaseSalesProductBookingPrice)({
|
|
4258
4405
|
...params,
|
|
4406
|
+
...(changedToFixed && !keepLegacyDayDuration ? {
|
|
4407
|
+
duration: undefined
|
|
4408
|
+
} : {}),
|
|
4259
4409
|
channel,
|
|
4260
4410
|
product,
|
|
4261
4411
|
fallback_price: authoritativeProduct ? undefined : params.fallback_price,
|
|
4262
4412
|
customer_id: customerId,
|
|
4263
4413
|
quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? undefined : quotation
|
|
4264
4414
|
});
|
|
4415
|
+
return changedToFixed ? {
|
|
4416
|
+
...result,
|
|
4417
|
+
pricing_method: {
|
|
4418
|
+
type: 'fixed_price'
|
|
4419
|
+
},
|
|
4420
|
+
duration: undefined
|
|
4421
|
+
} : result;
|
|
4265
4422
|
});
|
|
4266
4423
|
}
|
|
4424
|
+
setProductVoucherGroups(groups) {
|
|
4425
|
+
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
4426
|
+
this.store.order.setProductVoucherGroups(groups);
|
|
4427
|
+
}
|
|
4428
|
+
validateProductVoucherSelection() {
|
|
4429
|
+
this.store.order?.validateProductVoucherSelection();
|
|
4430
|
+
}
|
|
4267
4431
|
async addProductToOrder(product, booking, options) {
|
|
4268
4432
|
try {
|
|
4269
4433
|
if (!this.store.order) throw new Error('order 模块未初始化');
|
|
@@ -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>;
|