@pisell/pisellos 0.10.3 → 0.10.5
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/BaseModule.d.ts +1 -0
- package/dist/modules/BaseModule.js +24 -28
- package/dist/modules/Order/index.d.ts +13 -2
- package/dist/modules/Order/index.js +142 -60
- package/dist/modules/Order/types.d.ts +8 -1
- package/dist/modules/Order/utils.js +0 -1
- package/dist/solution/BaseSales/index.d.ts +3 -1
- package/dist/solution/BaseSales/index.js +98 -81
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +3 -1
- package/dist/solution/BookingTicket/index.js +71 -47
- package/dist/solution/UnifiedBookingSales/index.d.ts +9 -0
- package/dist/solution/UnifiedBookingSales/index.js +576 -321
- package/dist/solution/UnifiedBookingSales/types.d.ts +7 -0
- package/lib/model/strategy/adapter/promotion/index.js +51 -0
- package/lib/modules/BaseModule.d.ts +1 -0
- package/lib/modules/BaseModule.js +24 -37
- package/lib/modules/Order/index.d.ts +13 -2
- package/lib/modules/Order/index.js +90 -19
- package/lib/modules/Order/types.d.ts +8 -1
- package/lib/modules/Order/utils.js +0 -1
- package/lib/solution/BaseSales/index.d.ts +3 -1
- package/lib/solution/BaseSales/index.js +29 -16
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +3 -1
- package/lib/solution/BookingTicket/index.js +30 -7
- package/lib/solution/UnifiedBookingSales/index.d.ts +9 -0
- package/lib/solution/UnifiedBookingSales/index.js +135 -0
- package/lib/solution/UnifiedBookingSales/types.d.ts +7 -0
- package/package.json +1 -1
|
@@ -56,6 +56,7 @@ var import_utils = require("../../modules/Order/utils");
|
|
|
56
56
|
__reExport(BookingTicket_exports, require("./types"), module.exports);
|
|
57
57
|
var OPEN_DATA_SECTION_CODES = ["sale", "reservation", "fulfillment", "menu", "workflow"];
|
|
58
58
|
var OPEN_DATA_CACHE_TTL = 5 * 60 * 1e3;
|
|
59
|
+
var USER_PLATFORM = ["pc", "h5"];
|
|
59
60
|
function resolveBookingUidForAddTime(booking) {
|
|
60
61
|
var _a;
|
|
61
62
|
const uid = (_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.unique_identification_number;
|
|
@@ -135,6 +136,7 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
|
|
|
135
136
|
this.addTimeProductsCatalog = [];
|
|
136
137
|
this.orderCustomerDiscountRefreshInFlight = null;
|
|
137
138
|
this.orderCustomerDiscountRefreshCustomerId = null;
|
|
139
|
+
this.orderCustomerPromotionRefreshInFlight = null;
|
|
138
140
|
this.loadOpenDataConfigInFlight = null;
|
|
139
141
|
}
|
|
140
142
|
/**
|
|
@@ -352,7 +354,8 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
|
|
|
352
354
|
const scannedList = raw.scannedDiscountList || [];
|
|
353
355
|
const extractedCustomerId = this.getDiscountCustomerId(scannedList);
|
|
354
356
|
const hasOrderCustomer = Boolean(this.store.order.getOrderCustomer());
|
|
355
|
-
|
|
357
|
+
const isUserPlatform = USER_PLATFORM.includes(this.otherParams.platform);
|
|
358
|
+
if (!hasOrderCustomer && extractedCustomerId && !isUserPlatform) {
|
|
356
359
|
await this.hydrateOrderCustomerFromScanDiscounts(scannedList);
|
|
357
360
|
}
|
|
358
361
|
if (raw.isAvailable) {
|
|
@@ -899,9 +902,21 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
|
|
|
899
902
|
const next = this.buildOrderCustomerPayload();
|
|
900
903
|
this.core.effects.emit(`${this.name}:onOrderCustomerChange`, next);
|
|
901
904
|
this.refreshDiscountConfigAfterOrderCustomerChange(patch.customer_id);
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
+
const promotionRefreshTask = this.store.order.applyPromotion().then(() => void 0);
|
|
906
|
+
this.orderCustomerPromotionRefreshInFlight = promotionRefreshTask;
|
|
907
|
+
void promotionRefreshTask.then(
|
|
908
|
+
() => {
|
|
909
|
+
if (this.orderCustomerPromotionRefreshInFlight !== promotionRefreshTask)
|
|
910
|
+
return;
|
|
911
|
+
this.orderCustomerPromotionRefreshInFlight = null;
|
|
912
|
+
},
|
|
913
|
+
(error) => {
|
|
914
|
+
console.error("[BookingTicket] applyPromotion after customer change failed", error);
|
|
915
|
+
if (this.orderCustomerPromotionRefreshInFlight !== promotionRefreshTask)
|
|
916
|
+
return;
|
|
917
|
+
this.orderCustomerPromotionRefreshInFlight = null;
|
|
918
|
+
}
|
|
919
|
+
);
|
|
905
920
|
}
|
|
906
921
|
/**
|
|
907
922
|
* 读取 tempOrder 上的下单客户协议字段;customer_id 缺失时返回 null。
|
|
@@ -971,12 +986,13 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
|
|
|
971
986
|
}
|
|
972
987
|
refreshDiscountConfigAfterOrderCustomerChange(customerId) {
|
|
973
988
|
if (!customerId || customerId === 1)
|
|
974
|
-
return;
|
|
989
|
+
return Promise.resolve();
|
|
975
990
|
if (this.orderCustomerDiscountRefreshInFlight && this.orderCustomerDiscountRefreshCustomerId === customerId) {
|
|
976
|
-
return;
|
|
991
|
+
return this.orderCustomerDiscountRefreshInFlight;
|
|
977
992
|
}
|
|
978
993
|
const previousRefresh = this.orderCustomerDiscountRefreshInFlight;
|
|
979
994
|
const refreshTask = (async () => {
|
|
995
|
+
var _a, _b, _c, _d;
|
|
980
996
|
if (previousRefresh) {
|
|
981
997
|
await previousRefresh.catch(() => void 0);
|
|
982
998
|
}
|
|
@@ -984,7 +1000,10 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
|
|
|
984
1000
|
if (!currentCustomer || Number(currentCustomer.customer_id) !== customerId) {
|
|
985
1001
|
return;
|
|
986
1002
|
}
|
|
987
|
-
|
|
1003
|
+
const tempOrder = (_b = (_a = this.store.order).getTempOrder) == null ? void 0 : _b.call(_a);
|
|
1004
|
+
const orderId = (tempOrder == null ? void 0 : tempOrder.order_id) || ((_d = (_c = this.getOrderIdentity) == null ? void 0 : _c.call(this)) == null ? void 0 : _d.orderId);
|
|
1005
|
+
const action = !orderId || String(orderId).startsWith("local_order") ? "create" : "edit";
|
|
1006
|
+
await this.loadDiscountConfig({ customerId, action });
|
|
988
1007
|
})();
|
|
989
1008
|
this.orderCustomerDiscountRefreshInFlight = refreshTask;
|
|
990
1009
|
this.orderCustomerDiscountRefreshCustomerId = customerId;
|
|
@@ -996,6 +1015,10 @@ var BookingTicketImpl = class extends import_BaseSales.BaseSalesImpl {
|
|
|
996
1015
|
this.orderCustomerDiscountRefreshInFlight = null;
|
|
997
1016
|
this.orderCustomerDiscountRefreshCustomerId = null;
|
|
998
1017
|
});
|
|
1018
|
+
return refreshTask;
|
|
1019
|
+
}
|
|
1020
|
+
waitForOrderCustomerPromotionRefresh() {
|
|
1021
|
+
return this.orderCustomerPromotionRefreshInFlight || Promise.resolve();
|
|
999
1022
|
}
|
|
1000
1023
|
/**
|
|
1001
1024
|
* 获取客户分页信息
|
|
@@ -63,6 +63,8 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
63
63
|
private openDataTarget;
|
|
64
64
|
private loadOpenDataInFlight;
|
|
65
65
|
private loadOpenDataInFlightTarget;
|
|
66
|
+
protected isSessionStoragePersistEnabled(): boolean;
|
|
67
|
+
protected shouldUseSessionStorageForSubModule(moduleName?: string): boolean;
|
|
66
68
|
/**
|
|
67
69
|
* Kiosk 不能把已收款订单留在本地等待重试:默认直接等待云端 checkout。
|
|
68
70
|
* 兼容仍需要 WebPOS 待同步模式的入口可显式传 checkoutSyncTaskEnabled: true。
|
|
@@ -72,6 +74,13 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
72
74
|
protected getDefaultCheckoutSmallTicketDataFlag(): number;
|
|
73
75
|
protected getRegisteredModuleNames(): readonly string[];
|
|
74
76
|
protected createSubModule(moduleName: string): Module | null;
|
|
77
|
+
addNewOrder(): Promise<import("../../modules/Order/types").OrderTempOrder>;
|
|
78
|
+
syncAuthenticatedOrderCustomer(): Promise<boolean>;
|
|
79
|
+
private isAuthenticatedCustomerUserPlatform;
|
|
80
|
+
private resolveDiscountOrderIdentity;
|
|
81
|
+
private resolveDiscountAction;
|
|
82
|
+
private resetCachedCustomerDiscountState;
|
|
83
|
+
private refreshLegacySessionCustomerDiscounts;
|
|
75
84
|
/**
|
|
76
85
|
* Loads OpenData without borrowing BookingTicket. Cache ownership is tied to the exact
|
|
77
86
|
* business/channel target so a reused solution instance cannot leak another entry's menus.
|
|
@@ -141,6 +141,28 @@ function toNumberId(value) {
|
|
|
141
141
|
const parsed = Number(value);
|
|
142
142
|
return Number.isFinite(parsed) ? parsed : String(value);
|
|
143
143
|
}
|
|
144
|
+
function toCustomerId(value) {
|
|
145
|
+
const parsed = Number(value);
|
|
146
|
+
return Number.isFinite(parsed) && parsed > 1 ? parsed : null;
|
|
147
|
+
}
|
|
148
|
+
function resolveTempOrderCustomerId(tempOrder) {
|
|
149
|
+
var _a, _b, _c, _d, _e;
|
|
150
|
+
return toCustomerId(
|
|
151
|
+
(tempOrder == null ? void 0 : tempOrder.customer_id) || ((_a = tempOrder == null ? void 0 : tempOrder.customer) == null ? void 0 : _a.id) || ((_c = (_b = tempOrder == null ? void 0 : tempOrder._extend) == null ? void 0 : _b.customerSnapshot) == null ? void 0 : _c.id) || ((_e = (_d = tempOrder == null ? void 0 : tempOrder._extend) == null ? void 0 : _d.customerSnapshot) == null ? void 0 : _e.customer_id)
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
function isLocalOrderId(orderId) {
|
|
155
|
+
return typeof orderId === "string" && orderId.startsWith("local_order");
|
|
156
|
+
}
|
|
157
|
+
function isCustomerBoundDiscount(discount) {
|
|
158
|
+
const type = (discount == null ? void 0 : discount.type) ?? (discount == null ? void 0 : discount.tag);
|
|
159
|
+
return type === "good_pass" || type === "discount_card" || type === "product_discount_card";
|
|
160
|
+
}
|
|
161
|
+
function filterCustomerBoundDiscounts(discountList) {
|
|
162
|
+
if (!Array.isArray(discountList))
|
|
163
|
+
return [];
|
|
164
|
+
return discountList.filter((discount) => !isCustomerBoundDiscount(discount));
|
|
165
|
+
}
|
|
144
166
|
function resolveProductKind(product) {
|
|
145
167
|
var _a, _b, _c;
|
|
146
168
|
if (product.duration)
|
|
@@ -447,6 +469,15 @@ var UnifiedBookingSalesImpl = class extends import_BookingTicket.BookingTicket {
|
|
|
447
469
|
this.loadOpenDataInFlight = null;
|
|
448
470
|
this.loadOpenDataInFlightTarget = null;
|
|
449
471
|
}
|
|
472
|
+
isSessionStoragePersistEnabled() {
|
|
473
|
+
var _a;
|
|
474
|
+
return Boolean(
|
|
475
|
+
this.cacheId && ((_a = this.otherParams) == null ? void 0 : _a.enableSessionStoragePersist) === true
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
shouldUseSessionStorageForSubModule(moduleName) {
|
|
479
|
+
return this.isSessionStoragePersistEnabled() && moduleName === "order";
|
|
480
|
+
}
|
|
450
481
|
/**
|
|
451
482
|
* Kiosk 不能把已收款订单留在本地等待重试:默认直接等待云端 checkout。
|
|
452
483
|
* 兼容仍需要 WebPOS 待同步模式的入口可显式传 checkoutSyncTaskEnabled: true。
|
|
@@ -472,6 +503,110 @@ var UnifiedBookingSalesImpl = class extends import_BookingTicket.BookingTicket {
|
|
|
472
503
|
}
|
|
473
504
|
return super.createSubModule(moduleName);
|
|
474
505
|
}
|
|
506
|
+
async addNewOrder() {
|
|
507
|
+
var _a, _b, _c, _d;
|
|
508
|
+
const sessionRecord = this.isSessionStoragePersistEnabled() ? (_b = (_a = this.store.order) == null ? void 0 : _a.consumeSessionStorageRestore) == null ? void 0 : _b.call(_a) : null;
|
|
509
|
+
if (sessionRecord) {
|
|
510
|
+
await this.loadSalesDetail({
|
|
511
|
+
preloadedSalesDetail: sessionRecord,
|
|
512
|
+
hydrateSource: "sessionStorage"
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
const tempOrder = await super.addNewOrder();
|
|
516
|
+
if (sessionRecord) {
|
|
517
|
+
(_c = this.store.order) == null ? void 0 : _c.persistTempOrder();
|
|
518
|
+
}
|
|
519
|
+
if (this.isAuthenticatedCustomerUserPlatform()) {
|
|
520
|
+
try {
|
|
521
|
+
const didSyncAuthenticatedCustomer = await this.syncAuthenticatedOrderCustomer();
|
|
522
|
+
if (!didSyncAuthenticatedCustomer && sessionRecord) {
|
|
523
|
+
await this.refreshLegacySessionCustomerDiscounts(tempOrder);
|
|
524
|
+
}
|
|
525
|
+
} catch (error) {
|
|
526
|
+
console.warn(
|
|
527
|
+
"[UnifiedBookingSales] Failed to sync authenticated order customer after addNewOrder",
|
|
528
|
+
error
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
} else if (sessionRecord) {
|
|
532
|
+
try {
|
|
533
|
+
await this.refreshLegacySessionCustomerDiscounts(tempOrder);
|
|
534
|
+
} catch (error) {
|
|
535
|
+
console.warn(
|
|
536
|
+
"[UnifiedBookingSales] Failed to refresh cached customer discounts after addNewOrder",
|
|
537
|
+
error
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return ((_d = this.store.order) == null ? void 0 : _d.getTempOrder()) || tempOrder;
|
|
542
|
+
}
|
|
543
|
+
async syncAuthenticatedOrderCustomer() {
|
|
544
|
+
var _a, _b, _c, _d, _e, _f;
|
|
545
|
+
if (!this.isAuthenticatedCustomerUserPlatform())
|
|
546
|
+
return false;
|
|
547
|
+
const authenticatedCustomer = (_d = (_c = (_b = (_a = this.core) == null ? void 0 : _a.getPlugin) == null ? void 0 : _b.call(_a, "user")) == null ? void 0 : _c.get) == null ? void 0 : _d.call(_c);
|
|
548
|
+
const authenticatedCustomerId = toCustomerId(authenticatedCustomer == null ? void 0 : authenticatedCustomer.id);
|
|
549
|
+
if (!authenticatedCustomerId)
|
|
550
|
+
return false;
|
|
551
|
+
const tempOrder = this.getTempOrder();
|
|
552
|
+
const cachedCustomerId = resolveTempOrderCustomerId(tempOrder);
|
|
553
|
+
if (cachedCustomerId !== null && cachedCustomerId !== authenticatedCustomerId) {
|
|
554
|
+
await this.resetCachedCustomerDiscountState();
|
|
555
|
+
}
|
|
556
|
+
(_f = (_e = this.store.customer) == null ? void 0 : _e.setSelectedCustomer) == null ? void 0 : _f.call(_e, authenticatedCustomer);
|
|
557
|
+
this.setOrderCustomer(authenticatedCustomer);
|
|
558
|
+
await Promise.all([
|
|
559
|
+
this.refreshDiscountConfigAfterOrderCustomerChange(authenticatedCustomerId),
|
|
560
|
+
this.waitForOrderCustomerPromotionRefresh()
|
|
561
|
+
]);
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
isAuthenticatedCustomerUserPlatform() {
|
|
565
|
+
var _a;
|
|
566
|
+
const platform = String(((_a = this.otherParams) == null ? void 0 : _a.platform) || "").toLowerCase();
|
|
567
|
+
return platform === "pc" || platform === "h5";
|
|
568
|
+
}
|
|
569
|
+
resolveDiscountOrderIdentity(tempOrder) {
|
|
570
|
+
var _a, _b, _c;
|
|
571
|
+
return (tempOrder == null ? void 0 : tempOrder.order_id) || ((_c = (_b = (_a = this.store.order) == null ? void 0 : _a.getOrderIdentity) == null ? void 0 : _b.call(_a)) == null ? void 0 : _c.orderId) || null;
|
|
572
|
+
}
|
|
573
|
+
resolveDiscountAction(orderId) {
|
|
574
|
+
if (!orderId || isLocalOrderId(orderId))
|
|
575
|
+
return "create";
|
|
576
|
+
return "edit";
|
|
577
|
+
}
|
|
578
|
+
async resetCachedCustomerDiscountState() {
|
|
579
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
580
|
+
(_b = (_a = this.store.order) == null ? void 0 : _a.clearOrderCustomer) == null ? void 0 : _b.call(_a);
|
|
581
|
+
(_d = (_c = this.store.customer) == null ? void 0 : _c.setSelectedCustomer) == null ? void 0 : _d.call(_c, null);
|
|
582
|
+
this.discountConfigCacheKey = null;
|
|
583
|
+
this.hasManualDiscountSelection = false;
|
|
584
|
+
const orderStore = ((_e = this.store.order) == null ? void 0 : _e.store) || {};
|
|
585
|
+
const discountModule = orderStore.discount;
|
|
586
|
+
const filteredOriginalDiscounts = filterCustomerBoundDiscounts(
|
|
587
|
+
((_f = discountModule == null ? void 0 : discountModule.getOriginalDiscountList) == null ? void 0 : _f.call(discountModule)) || []
|
|
588
|
+
);
|
|
589
|
+
const filteredCurrentDiscounts = filterCustomerBoundDiscounts(
|
|
590
|
+
((_g = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _g.call(discountModule)) || []
|
|
591
|
+
);
|
|
592
|
+
await ((_h = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _h.call(discountModule, filteredOriginalDiscounts));
|
|
593
|
+
await ((_i = discountModule == null ? void 0 : discountModule.setDiscountList) == null ? void 0 : _i.call(discountModule, filteredCurrentDiscounts));
|
|
594
|
+
(_k = (_j = this.store.order) == null ? void 0 : _j.applyDiscount) == null ? void 0 : _k.call(_j);
|
|
595
|
+
await ((_m = (_l = this.store.order) == null ? void 0 : _l.recalculateSummary) == null ? void 0 : _m.call(_l, { createIfMissing: true }));
|
|
596
|
+
(_o = (_n = this.store.order) == null ? void 0 : _n.persistTempOrder) == null ? void 0 : _o.call(_n);
|
|
597
|
+
}
|
|
598
|
+
async refreshLegacySessionCustomerDiscounts(tempOrder) {
|
|
599
|
+
const customerId = resolveTempOrderCustomerId(tempOrder);
|
|
600
|
+
if (!customerId)
|
|
601
|
+
return void 0;
|
|
602
|
+
const loadDiscountConfig = super.loadDiscountConfig.bind(this);
|
|
603
|
+
return await loadDiscountConfig({
|
|
604
|
+
customerId,
|
|
605
|
+
action: this.resolveDiscountAction(
|
|
606
|
+
this.resolveDiscountOrderIdentity(tempOrder)
|
|
607
|
+
)
|
|
608
|
+
});
|
|
609
|
+
}
|
|
475
610
|
/**
|
|
476
611
|
* Loads OpenData without borrowing BookingTicket. Cache ownership is tied to the exact
|
|
477
612
|
* business/channel target so a reused solution instance cannot leak another entry's menus.
|
|
@@ -11,6 +11,13 @@ export declare enum UnifiedBookingSalesHooks {
|
|
|
11
11
|
export interface UnifiedBookingSalesState extends BookingTicketState {
|
|
12
12
|
resourcePlanner: ResourcePlannerModule;
|
|
13
13
|
}
|
|
14
|
+
export interface UnifiedBookingSalesOtherParams extends Record<string, any> {
|
|
15
|
+
/**
|
|
16
|
+
* Persist the active order workspace in sessionStorage, partitioned by cacheId.
|
|
17
|
+
* Disabled by default and ignored when cacheId is missing.
|
|
18
|
+
*/
|
|
19
|
+
enableSessionStoragePersist?: boolean;
|
|
20
|
+
}
|
|
14
21
|
/** Explicit OpenData target used by page-level UnifiedBookingSales skins. */
|
|
15
22
|
export interface UnifiedBookingSalesLoadOpenDataParams {
|
|
16
23
|
businessCode: string;
|