@pisell/pisellos 0.10.4 → 0.10.6

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.
@@ -497,7 +497,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
497
497
  generateIdempotencyToken(): string;
498
498
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
499
499
  createOrder(params: CommitOrderParams['query']): {
500
- type: "appointment_booking" | "virtual";
500
+ type: "virtual" | "appointment_booking";
501
501
  platform: string;
502
502
  sales_channel: string;
503
503
  order_sales_channel: string;
@@ -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)
@@ -41,6 +41,10 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
41
41
  * paymentModule.updateOtherParams({ fatherModule: 'bookingTicket' });
42
42
  */
43
43
  updateOtherParams(params: Record<string, any>): void;
44
+ /**
45
+ * 获取标准化后的宿主平台标识,供支付子能力做平台边界判断。
46
+ */
47
+ getPlatform(): string;
44
48
  private getPaymentNumberAppData;
45
49
  /**
46
50
  * 记录信息日志
@@ -139,6 +139,13 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
139
139
  updateOtherParams(params) {
140
140
  this.otherParams = params || {};
141
141
  }
142
+ /**
143
+ * 获取标准化后的宿主平台标识,供支付子能力做平台边界判断。
144
+ */
145
+ getPlatform() {
146
+ var _a;
147
+ return String(((_a = this.otherParams) == null ? void 0 : _a.platform) || "").trim().toLowerCase();
148
+ }
142
149
  getPaymentNumberAppData(key) {
143
150
  var _a, _b, _c, _d, _e, _f, _g;
144
151
  const getData = (_b = (_a = this.appPlugin) == null ? void 0 : _a.getData) == null ? void 0 : _b.call(_a);
@@ -638,6 +638,18 @@ var WalletPassPaymentImpl = class {
638
638
  this.paymentModule.logInfo("[WalletPass] 商品列表为空,跳过获取用户识别码列表");
639
639
  return [];
640
640
  }
641
+ const platform = this.paymentModule.getPlatform();
642
+ if (platform === "pc" || platform === "h5") {
643
+ this.userIdentificationCodes = [];
644
+ this.emitEvent(import_types.WalletPassHooks.OnUserIdentificationCodesUpdated, {
645
+ userIdentificationCodes: []
646
+ });
647
+ this.paymentModule.logInfo(
648
+ "[WalletPass] 用户端平台跳过获取用户识别码列表",
649
+ { platform }
650
+ );
651
+ return [];
652
+ }
641
653
  if (typeof newParams.payment_order_id === "string" && newParams.payment_order_id.startsWith("LOCAL_")) {
642
654
  newParams.payment_order_id = void 0;
643
655
  }
@@ -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
- private refreshDiscountConfigAfterOrderCustomerChange;
286
+ protected refreshDiscountConfigAfterOrderCustomerChange(customerId: number | null): Promise<void>;
287
+ protected waitForOrderCustomerPromotionRefresh(): Promise<void>;
286
288
  /**
287
289
  * 获取客户分页信息
288
290
  * @returns 分页信息
@@ -326,7 +328,7 @@ export declare class BookingTicketImpl extends BaseSalesImpl implements Module {
326
328
  * 获取当前的客户搜索条件
327
329
  * @returns 当前搜索条件
328
330
  */
329
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
331
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
330
332
  /**
331
333
  * 获取客户列表状态(包含滚动加载相关状态)
332
334
  * @returns 客户状态
@@ -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
- if (!hasOrderCustomer && extractedCustomerId) {
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
- void this.store.order.applyPromotion().catch((error) => {
903
- console.error("[BookingTicket] applyPromotion after customer change failed", error);
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
- await this.loadDiscountConfig({ customerId });
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, _e, _f, _g, _h, _i;
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 (!sessionRecord)
488
- return super.addNewOrder();
489
- await this.loadSalesDetail({
490
- preloadedSalesDetail: sessionRecord,
491
- hydrateSource: "sessionStorage"
492
- });
509
+ if (sessionRecord) {
510
+ await this.loadSalesDetail({
511
+ preloadedSalesDetail: sessionRecord,
512
+ hydrateSource: "sessionStorage"
513
+ });
514
+ }
493
515
  const tempOrder = await super.addNewOrder();
494
- (_c = this.store.order) == null ? void 0 : _c.persistTempOrder();
495
- const customerId = Number(
496
- tempOrder.customer_id || ((_d = tempOrder.customer) == null ? void 0 : _d.id) || ((_f = (_e = tempOrder._extend) == null ? void 0 : _e.customerSnapshot) == null ? void 0 : _f.id) || ((_h = (_g = tempOrder._extend) == null ? void 0 : _g.customerSnapshot) == null ? void 0 : _h.customer_id) || 0
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.loadDiscountConfig({
501
- customerId,
502
- action: tempOrder.order_id ? "edit" : "create"
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 session restore",
536
+ "[UnifiedBookingSales] Failed to refresh cached customer discounts after addNewOrder",
507
537
  error
508
538
  );
509
539
  }
510
540
  }
511
- return ((_i = this.store.order) == null ? void 0 : _i.getTempOrder()) || tempOrder;
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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.10.4",
4
+ "version": "0.10.6",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",