@pisell/pisellos 0.10.4 → 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/Order/utils.js +0 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingTicket/index.d.ts +16 -2
- package/dist/solution/BookingTicket/index.js +71 -47
- package/dist/solution/UnifiedBookingSales/index.d.ts +6 -0
- package/dist/solution/UnifiedBookingSales/index.js +531 -344
- package/lib/modules/Order/utils.js +0 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.d.ts +16 -2
- package/lib/solution/BookingTicket/index.js +30 -7
- package/lib/solution/UnifiedBookingSales/index.d.ts +6 -0
- package/lib/solution/UnifiedBookingSales/index.js +115 -18
- package/package.json +1 -1
|
@@ -1203,7 +1203,6 @@ function productRequiresFormSubject(tempOrder, product) {
|
|
|
1203
1203
|
}
|
|
1204
1204
|
function resolveIsFormSubject(tempOrder, product) {
|
|
1205
1205
|
var _a;
|
|
1206
|
-
debugger;
|
|
1207
1206
|
if (((_a = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _a.type) === "form")
|
|
1208
1207
|
return true;
|
|
1209
1208
|
if (product)
|
|
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
|
|
|
326
326
|
date: string;
|
|
327
327
|
status: string;
|
|
328
328
|
week: string;
|
|
329
|
-
weekNum: 0 |
|
|
329
|
+
weekNum: 0 | 5 | 2 | 1 | 6 | 4 | 3;
|
|
330
330
|
}[]>;
|
|
331
331
|
submitTimeSlot(timeSlots: TimeSliceItem): void;
|
|
332
332
|
private getScheduleDataByIds;
|
|
@@ -29,6 +29,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
29
29
|
private addTimeProductsCatalog;
|
|
30
30
|
private orderCustomerDiscountRefreshInFlight;
|
|
31
31
|
private orderCustomerDiscountRefreshCustomerId;
|
|
32
|
+
private orderCustomerPromotionRefreshInFlight;
|
|
32
33
|
private loadOpenDataConfigInFlight;
|
|
33
34
|
/**
|
|
34
35
|
* 在 BaseSales 默认模块清单(products/order/salesSummary/schedule)基础上追加 customer + bookingContext。
|
|
@@ -282,7 +283,8 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
282
283
|
restoreOrder(): Promise<import("../../modules/Order/types").OrderTempOrder>;
|
|
283
284
|
/** 内部:基于 OrderModule 当前状态构造一份 OrderCustomerChangePayload。 */
|
|
284
285
|
private buildOrderCustomerPayload;
|
|
285
|
-
|
|
286
|
+
protected refreshDiscountConfigAfterOrderCustomerChange(customerId: number | null): Promise<void>;
|
|
287
|
+
protected waitForOrderCustomerPromotionRefresh(): Promise<void>;
|
|
286
288
|
/**
|
|
287
289
|
* 获取客户分页信息
|
|
288
290
|
* @returns 分页信息
|
|
@@ -445,7 +447,19 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
|
|
|
445
447
|
* 加车两阶段主决策(规格弹窗 / 资源编辑 / 直接加车)。
|
|
446
448
|
* 与 ticketBooking `handleSelectProduct` + `handleBooking4Service` 等价。
|
|
447
449
|
*/
|
|
448
|
-
decideAddProduct(item: any, options?: Partial<AddProductDecideContext>):
|
|
450
|
+
decideAddProduct(item: any, options?: Partial<AddProductDecideContext>): {
|
|
451
|
+
action: "reloadCatalog";
|
|
452
|
+
} | {
|
|
453
|
+
action: "add";
|
|
454
|
+
cacheItem: any;
|
|
455
|
+
} | {
|
|
456
|
+
action: "requiresDetail";
|
|
457
|
+
payload: AddProductRequiresDetailPayload;
|
|
458
|
+
} | {
|
|
459
|
+
action: "requiresBookingEdit";
|
|
460
|
+
cacheItem: any;
|
|
461
|
+
payload: import("./utils/addProductDecision").AddProductRequiresBookingEditPayload;
|
|
462
|
+
};
|
|
449
463
|
/** 规格弹窗 callback 后的第二段决策。 */
|
|
450
464
|
decideAfterDetail(cacheItem: any, options?: Partial<AddProductDecideContext>): import("./utils/addProductDecision").AddProductDecision;
|
|
451
465
|
/**
|
|
@@ -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
|
* 获取客户分页信息
|
|
@@ -75,6 +75,12 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
|
|
|
75
75
|
protected getRegisteredModuleNames(): readonly string[];
|
|
76
76
|
protected createSubModule(moduleName: string): Module | null;
|
|
77
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;
|
|
78
84
|
/**
|
|
79
85
|
* Loads OpenData without borrowing BookingTicket. Cache ownership is tied to the exact
|
|
80
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)
|
|
@@ -482,33 +504,108 @@ var UnifiedBookingSalesImpl = class extends import_BookingTicket.BookingTicket {
|
|
|
482
504
|
return super.createSubModule(moduleName);
|
|
483
505
|
}
|
|
484
506
|
async addNewOrder() {
|
|
485
|
-
var _a, _b, _c, _d
|
|
507
|
+
var _a, _b, _c, _d;
|
|
486
508
|
const sessionRecord = this.isSessionStoragePersistEnabled() ? (_b = (_a = this.store.order) == null ? void 0 : _a.consumeSessionStorageRestore) == null ? void 0 : _b.call(_a) : null;
|
|
487
|
-
if (
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
509
|
+
if (sessionRecord) {
|
|
510
|
+
await this.loadSalesDetail({
|
|
511
|
+
preloadedSalesDetail: sessionRecord,
|
|
512
|
+
hydrateSource: "sessionStorage"
|
|
513
|
+
});
|
|
514
|
+
}
|
|
493
515
|
const tempOrder = await super.addNewOrder();
|
|
494
|
-
(
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
)
|
|
498
|
-
if (customerId > 1) {
|
|
516
|
+
if (sessionRecord) {
|
|
517
|
+
(_c = this.store.order) == null ? void 0 : _c.persistTempOrder();
|
|
518
|
+
}
|
|
519
|
+
if (this.isAuthenticatedCustomerUserPlatform()) {
|
|
499
520
|
try {
|
|
500
|
-
await this.
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
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);
|
|
504
534
|
} catch (error) {
|
|
505
535
|
console.warn(
|
|
506
|
-
"[UnifiedBookingSales] Failed to refresh discounts after
|
|
536
|
+
"[UnifiedBookingSales] Failed to refresh cached customer discounts after addNewOrder",
|
|
507
537
|
error
|
|
508
538
|
);
|
|
509
539
|
}
|
|
510
540
|
}
|
|
511
|
-
return ((
|
|
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
|
+
});
|
|
512
609
|
}
|
|
513
610
|
/**
|
|
514
611
|
* Loads OpenData without borrowing BookingTicket. Cache ownership is tied to the exact
|