@pisell/pisellos 0.10.6 → 0.10.8

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.
Files changed (64) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +12 -10
  3. package/dist/modules/Order/index.d.ts +14 -6
  4. package/dist/modules/Order/index.js +373 -246
  5. package/dist/modules/Order/types.d.ts +26 -3
  6. package/dist/modules/Order/types.js +11 -0
  7. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  8. package/dist/modules/Order/utils/discountProductLineIdentity.js +227 -0
  9. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +15 -0
  10. package/dist/modules/Order/utils/orderCollectionIdentity.js +75 -0
  11. package/dist/modules/Rules/index.js +125 -52
  12. package/dist/modules/SalesSummary/utils.js +7 -1
  13. package/dist/server/index.d.ts +6 -0
  14. package/dist/server/index.js +810 -729
  15. package/dist/server/modules/order/index.d.ts +1 -0
  16. package/dist/server/modules/order/index.js +9 -2
  17. package/dist/server/modules/order/types.d.ts +1 -1
  18. package/dist/solution/BaseSales/index.d.ts +15 -5
  19. package/dist/solution/BaseSales/index.js +211 -159
  20. package/dist/solution/BaseSales/utils/cartPromotion.js +26 -3
  21. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  22. package/dist/solution/BaseSales/utils.js +31 -20
  23. package/dist/solution/BookingByStep/index.d.ts +1 -1
  24. package/dist/solution/BookingTicket/index.d.ts +13 -1
  25. package/dist/solution/BookingTicket/index.js +19 -22
  26. package/dist/solution/BookingTicket/types.d.ts +3 -0
  27. package/dist/solution/BookingTicket/utils/cartView.js +44 -32
  28. package/dist/solution/Sales/index.d.ts +1 -0
  29. package/dist/solution/Sales/index.js +16 -2
  30. package/dist/solution/ScanOrder/utils.js +31 -20
  31. package/dist/solution/UnifiedBookingSales/index.d.ts +16 -4
  32. package/dist/solution/UnifiedBookingSales/index.js +113 -48
  33. package/lib/model/strategy/adapter/promotion/index.js +0 -51
  34. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -1
  35. package/lib/modules/Order/index.d.ts +14 -6
  36. package/lib/modules/Order/index.js +192 -52
  37. package/lib/modules/Order/types.d.ts +26 -3
  38. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  39. package/lib/modules/Order/utils/discountProductLineIdentity.js +170 -0
  40. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +15 -0
  41. package/lib/modules/Order/utils/orderCollectionIdentity.js +70 -0
  42. package/lib/modules/Rules/index.js +100 -20
  43. package/lib/modules/SalesSummary/utils.js +5 -1
  44. package/lib/server/index.d.ts +6 -0
  45. package/lib/server/index.js +51 -0
  46. package/lib/server/modules/order/index.d.ts +1 -0
  47. package/lib/server/modules/order/index.js +9 -3
  48. package/lib/server/modules/order/types.d.ts +1 -1
  49. package/lib/solution/BaseSales/index.d.ts +15 -5
  50. package/lib/solution/BaseSales/index.js +64 -16
  51. package/lib/solution/BaseSales/utils/cartPromotion.js +26 -2
  52. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -1
  53. package/lib/solution/BaseSales/utils.js +29 -18
  54. package/lib/solution/BookingByStep/index.d.ts +1 -1
  55. package/lib/solution/BookingTicket/index.d.ts +13 -1
  56. package/lib/solution/BookingTicket/index.js +6 -9
  57. package/lib/solution/BookingTicket/types.d.ts +3 -0
  58. package/lib/solution/BookingTicket/utils/cartView.js +43 -30
  59. package/lib/solution/Sales/index.d.ts +1 -0
  60. package/lib/solution/Sales/index.js +15 -3
  61. package/lib/solution/ScanOrder/utils.js +29 -18
  62. package/lib/solution/UnifiedBookingSales/index.d.ts +16 -4
  63. package/lib/solution/UnifiedBookingSales/index.js +80 -26
  64. package/package.json +1 -1
@@ -357,33 +357,44 @@ function attachItemRuleLimitsToTopLevelProducts(productList, limits) {
357
357
  return productList;
358
358
  }
359
359
  function buildProductLineFingerprint(productOptionItem, productBundle) {
360
- const optArr = Array.isArray(productOptionItem) ? productOptionItem : [];
361
- const normalizedOpts = optArr.map((item) => ({
362
- option_group_item_id: Number(item == null ? void 0 : item.option_group_item_id) || 0,
363
- option_group_id: Number(item == null ? void 0 : item.option_group_id) || 0,
364
- num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1,
365
- price: String((item == null ? void 0 : item.add_price) ?? (item == null ? void 0 : item.price) ?? "")
366
- })).sort((p, q) => {
367
- if (p.option_group_item_id !== q.option_group_item_id) {
368
- return p.option_group_item_id - q.option_group_item_id;
369
- }
370
- if (p.option_group_id !== q.option_group_id)
371
- return p.option_group_id - q.option_group_id;
372
- if (p.num !== q.num)
373
- return p.num - q.num;
374
- return p.price.localeCompare(q.price);
375
- });
360
+ const normalizeOptions = (options) => {
361
+ const optionArr = Array.isArray(options) ? options : [];
362
+ return optionArr.map((item) => ({
363
+ option_group_item_id: Number(item == null ? void 0 : item.option_group_item_id) || 0,
364
+ option_group_id: Number(item == null ? void 0 : item.option_group_id) || 0,
365
+ num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1,
366
+ price: String((item == null ? void 0 : item.add_price) ?? (item == null ? void 0 : item.price) ?? "")
367
+ })).sort((p, q) => {
368
+ if (p.option_group_item_id !== q.option_group_item_id) {
369
+ return p.option_group_item_id - q.option_group_item_id;
370
+ }
371
+ if (p.option_group_id !== q.option_group_id) {
372
+ return p.option_group_id - q.option_group_id;
373
+ }
374
+ if (p.num !== q.num)
375
+ return p.num - q.num;
376
+ return p.price.localeCompare(q.price);
377
+ });
378
+ };
379
+ const normalizedOpts = normalizeOptions(productOptionItem);
376
380
  const bundleArr = Array.isArray(productBundle) ? productBundle : [];
377
381
  const normalizedBundles = bundleArr.map((item) => ({
378
382
  bundle_id: Number((item == null ? void 0 : item.bundle_id) ?? (item == null ? void 0 : item.id) ?? 0) || 0,
379
383
  product_id: Number(item == null ? void 0 : item.product_id) || 0,
380
- num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1
384
+ product_variant_id: Number((item == null ? void 0 : item.bundle_variant_id) ?? (item == null ? void 0 : item.product_variant_id)) || 0,
385
+ num: typeof (item == null ? void 0 : item.num) === "number" && !Number.isNaN(item.num) ? Math.max(1, Math.floor(item.num)) : 1,
386
+ option: normalizeOptions(item == null ? void 0 : item.option)
381
387
  })).sort((p, q) => {
382
388
  if (p.bundle_id !== q.bundle_id)
383
389
  return p.bundle_id - q.bundle_id;
384
390
  if (p.product_id !== q.product_id)
385
391
  return p.product_id - q.product_id;
386
- return p.num - q.num;
392
+ if (p.product_variant_id !== q.product_variant_id) {
393
+ return p.product_variant_id - q.product_variant_id;
394
+ }
395
+ if (p.num !== q.num)
396
+ return p.num - q.num;
397
+ return JSON.stringify(p.option).localeCompare(JSON.stringify(q.option));
387
398
  });
388
399
  return JSON.stringify([normalizedOpts, normalizedBundles]);
389
400
  }
@@ -63,8 +63,24 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
63
63
  private openDataTarget;
64
64
  private loadOpenDataInFlight;
65
65
  private loadOpenDataInFlightTarget;
66
+ protected getSubmitOrderSalesChannel(): string;
66
67
  protected isSessionStoragePersistEnabled(): boolean;
67
68
  protected shouldUseSessionStorageForSubModule(moduleName?: string): boolean;
69
+ /**
70
+ * 读取与当前 cacheId 同分桶的 Solution 会话状态。
71
+ * 该状态独立于 otherParams,适合页面皮肤保存短生命周期 UI 状态。
72
+ */
73
+ getSessionStateValue<T = unknown>(key: string): T | undefined;
74
+ /**
75
+ * 写入与当前 cacheId 同分桶的 Solution 会话状态。
76
+ * value 为 undefined 时删除该 key;存储失败不阻断业务流程。
77
+ */
78
+ setSessionStateValue(key: string, value: unknown): void;
79
+ /**
80
+ * 清除当前 cacheId 的可恢复订单快照,同时保留 Solution UI sessionState。
81
+ * 用于支付跳转等终态场景,避免浏览器返回时恢复已提交订单。
82
+ */
83
+ clearSessionStorageOrderSnapshot(): void;
68
84
  /**
69
85
  * Kiosk 不能把已收款订单留在本地等待重试:默认直接等待云端 checkout。
70
86
  * 兼容仍需要 WebPOS 待同步模式的入口可显式传 checkoutSyncTaskEnabled: true。
@@ -111,10 +127,6 @@ export declare class UnifiedBookingSalesImpl extends BookingTicket {
111
127
  * Read-only compatibility view for salesSdk skins. It reconnects a booking to its product but
112
128
  * must not be used to mutate tempOrder; all writes go through BaseSales / planner APIs.
113
129
  */
114
- getCart(): {
115
- items: any[];
116
- bookings: any[];
117
- };
118
130
  /**
119
131
  * Loads the current customer's product coupons and discount cards after planner lines exist,
120
132
  * then optionally lets the existing Rules engine select the best valid combination. This is a
@@ -49,6 +49,9 @@ var import_BookingTicket = require("../BookingTicket");
49
49
  __reExport(UnifiedBookingSales_exports, require("./types"), module.exports);
50
50
  var OPEN_DATA_SECTION_CODES = ["sale", "reservation", "fulfillment", "menu", "workflow"];
51
51
  var OPEN_DATA_CACHE_TTL = 5 * 60 * 1e3;
52
+ function isRecord(value) {
53
+ return !!value && typeof value === "object" && !Array.isArray(value);
54
+ }
52
55
  function pickLocalizedText(value) {
53
56
  if (!value)
54
57
  return void 0;
@@ -469,6 +472,11 @@ var UnifiedBookingSalesImpl = class extends import_BookingTicket.BookingTicket {
469
472
  this.loadOpenDataInFlight = null;
470
473
  this.loadOpenDataInFlightTarget = null;
471
474
  }
475
+ getSubmitOrderSalesChannel() {
476
+ var _a;
477
+ const channel = String(((_a = this.otherParams) == null ? void 0 : _a.channel) ?? "").trim();
478
+ return channel || super.getSubmitOrderSalesChannel();
479
+ }
472
480
  isSessionStoragePersistEnabled() {
473
481
  var _a;
474
482
  return Boolean(
@@ -478,6 +486,51 @@ var UnifiedBookingSalesImpl = class extends import_BookingTicket.BookingTicket {
478
486
  shouldUseSessionStorageForSubModule(moduleName) {
479
487
  return this.isSessionStoragePersistEnabled() && moduleName === "order";
480
488
  }
489
+ /**
490
+ * 读取与当前 cacheId 同分桶的 Solution 会话状态。
491
+ * 该状态独立于 otherParams,适合页面皮肤保存短生命周期 UI 状态。
492
+ */
493
+ getSessionStateValue(key) {
494
+ if (!key || !this.isSessionStoragePersistEnabled())
495
+ return void 0;
496
+ const cacheData = this.readSessionCacheData();
497
+ const solutionCache = cacheData == null ? void 0 : cacheData[this.name];
498
+ if (!isRecord(solutionCache) || !isRecord(solutionCache.sessionState)) {
499
+ return void 0;
500
+ }
501
+ return solutionCache.sessionState[key];
502
+ }
503
+ /**
504
+ * 写入与当前 cacheId 同分桶的 Solution 会话状态。
505
+ * value 为 undefined 时删除该 key;存储失败不阻断业务流程。
506
+ */
507
+ setSessionStateValue(key, value) {
508
+ if (!key || !this.isSessionStoragePersistEnabled())
509
+ return;
510
+ const cacheData = this.readSessionCacheData();
511
+ const solutionCache = cacheData == null ? void 0 : cacheData[this.name];
512
+ const currentSessionState = isRecord(solutionCache) && isRecord(solutionCache.sessionState) ? solutionCache.sessionState : {};
513
+ const nextSessionState = { ...currentSessionState };
514
+ if (value === void 0) {
515
+ delete nextSessionState[key];
516
+ } else {
517
+ nextSessionState[key] = value;
518
+ }
519
+ this.checkSaveCache({
520
+ cacheId: this.cacheId,
521
+ fatherModule: this.name,
522
+ store: { sessionState: nextSessionState },
523
+ cacheKey: ["sessionState"]
524
+ });
525
+ }
526
+ /**
527
+ * 清除当前 cacheId 的可恢复订单快照,同时保留 Solution UI sessionState。
528
+ * 用于支付跳转等终态场景,避免浏览器返回时恢复已提交订单。
529
+ */
530
+ clearSessionStorageOrderSnapshot() {
531
+ var _a, _b;
532
+ (_b = (_a = this.store.order) == null ? void 0 : _a.clearSessionStoragePersistedTempOrder) == null ? void 0 : _b.call(_a);
533
+ }
481
534
  /**
482
535
  * Kiosk 不能把已收款订单留在本地等待重试:默认直接等待云端 checkout。
483
536
  * 兼容仍需要 WebPOS 待同步模式的入口可显式传 checkoutSyncTaskEnabled: true。
@@ -761,32 +814,33 @@ var UnifiedBookingSalesImpl = class extends import_BookingTicket.BookingTicket {
761
814
  * Read-only compatibility view for salesSdk skins. It reconnects a booking to its product but
762
815
  * must not be used to mutate tempOrder; all writes go through BaseSales / planner APIs.
763
816
  */
764
- getCart() {
765
- const tempOrder = this.getTempOrder();
766
- const salesDetail = this.getSalesOrder();
767
- const items = (tempOrder == null ? void 0 : tempOrder.products) || [];
768
- const bookings = (salesDetail == null ? void 0 : salesDetail.bookings) || (tempOrder == null ? void 0 : tempOrder.bookings) || [];
769
- return {
770
- items,
771
- bookings: bookings.map((booking) => {
772
- const productUid = booking == null ? void 0 : booking.product_uid;
773
- const product = productUid ? items.find((item) => {
774
- var _a;
775
- const uid = ((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.unique_identification_number) || (item == null ? void 0 : item.unique_identification_number);
776
- return String(uid || "") === String(productUid);
777
- }) || null : null;
778
- return {
779
- ...booking,
780
- _extend: {
781
- ...(booking == null ? void 0 : booking._extend) || {},
782
- product,
783
- addTimeProduct: [],
784
- canAddTime: false
785
- }
786
- };
787
- })
788
- };
789
- }
817
+ // getCart(): BookingTicketCartView {
818
+ // const tempOrder = this.getTempOrder();
819
+ // const salesDetail = this.getSalesOrder();
820
+ // const items = tempOrder?.products || [];
821
+ // const bookings = salesDetail?.bookings || tempOrder?.bookings || [];
822
+ // return {
823
+ // items,
824
+ // bookings: bookings.map((booking: any) => {
825
+ // const productUid = booking?.product_uid;
826
+ // const product = productUid
827
+ // ? items.find((item: any) => {
828
+ // const uid = item?.metadata?.unique_identification_number || item?.unique_identification_number;
829
+ // return String(uid || '') === String(productUid);
830
+ // }) || null
831
+ // : null;
832
+ // return {
833
+ // ...booking,
834
+ // _extend: {
835
+ // ...(booking?._extend || {}),
836
+ // product,
837
+ // addTimeProduct: [],
838
+ // canAddTime: false,
839
+ // },
840
+ // };
841
+ // }),
842
+ // };
843
+ // }
790
844
  /**
791
845
  * Loads the current customer's product coupons and discount cards after planner lines exist,
792
846
  * then optionally lets the existing Rules engine select the best valid combination. This is a
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.10.6",
4
+ "version": "0.10.8",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",