@pisell/pisellos 2.2.261 → 2.2.262

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 (134) hide show
  1. package/dist/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  2. package/dist/model/strategy/adapter/dataVariant/adapter.js +167 -0
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  4. package/dist/model/strategy/adapter/dataVariant/evaluator.js +780 -0
  5. package/dist/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  6. package/dist/model/strategy/adapter/dataVariant/examples.js +277 -0
  7. package/dist/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  8. package/dist/model/strategy/adapter/dataVariant/index.js +4 -0
  9. package/dist/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  10. package/dist/model/strategy/adapter/dataVariant/type.js +54 -0
  11. package/dist/model/strategy/adapter/index.d.ts +4 -0
  12. package/dist/model/strategy/adapter/index.js +5 -1
  13. package/dist/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  14. package/dist/model/strategy/adapter/promotion/adapter.js +0 -23
  15. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  16. package/dist/model/strategy/adapter/promotion/evaluator.js +6 -279
  17. package/dist/model/strategy/adapter/promotion/examples.d.ts +0 -86
  18. package/dist/model/strategy/adapter/promotion/examples.js +0 -99
  19. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  20. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  21. package/dist/model/strategy/adapter/promotion/type.d.ts +2 -90
  22. package/dist/model/strategy/adapter/promotion/type.js +0 -45
  23. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +16 -10
  24. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  25. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  26. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +32 -1
  27. package/dist/modules/Discount/index.d.ts +5 -2
  28. package/dist/modules/Discount/index.js +30 -7
  29. package/dist/modules/Discount/types.d.ts +4 -0
  30. package/dist/modules/Order/index.d.ts +14 -2
  31. package/dist/modules/Order/index.js +1035 -736
  32. package/dist/modules/Order/types.d.ts +16 -0
  33. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  34. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  35. package/dist/modules/Order/utils.d.ts +4 -3
  36. package/dist/modules/Order/utils.js +54 -61
  37. package/dist/modules/Product/types.d.ts +22 -0
  38. package/dist/modules/ProductList/index.d.ts +1 -1
  39. package/dist/modules/ProductList/index.js +4 -2
  40. package/dist/modules/ProductList/types.d.ts +2 -0
  41. package/dist/modules/Rules/index.d.ts +2 -9
  42. package/dist/modules/Rules/index.js +69 -43
  43. package/dist/modules/Rules/types.d.ts +10 -1
  44. package/dist/server/index.d.ts +55 -0
  45. package/dist/server/index.js +1161 -742
  46. package/dist/server/modules/order/index.d.ts +10 -4
  47. package/dist/server/modules/order/index.js +404 -399
  48. package/dist/server/modules/order/types.d.ts +4 -0
  49. package/dist/server/modules/products/index.d.ts +31 -8
  50. package/dist/server/modules/products/index.js +549 -390
  51. package/dist/server/modules/products/types.d.ts +18 -0
  52. package/dist/solution/BaseSales/index.d.ts +21 -1
  53. package/dist/solution/BaseSales/index.js +1136 -789
  54. package/dist/solution/BaseSales/types.d.ts +6 -1
  55. package/dist/solution/BaseSales/types.js +1 -1
  56. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  57. package/dist/solution/BaseSales/utils/cartPromotion.js +48 -81
  58. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  59. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  60. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +14 -1
  61. package/dist/solution/BookingByStep/index.d.ts +1 -1
  62. package/dist/solution/BookingTicket/index.d.ts +1 -1
  63. package/dist/solution/BookingTicket/index.js +59 -25
  64. package/dist/solution/BookingTicket/types.d.ts +2 -0
  65. package/dist/solution/ScanOrder/index.js +20 -31
  66. package/dist/solution/ShopDiscount/index.js +15 -14
  67. package/dist/solution/VenueBooking/index.js +19 -30
  68. package/lib/model/strategy/adapter/dataVariant/adapter.d.ts +50 -0
  69. package/lib/model/strategy/adapter/dataVariant/adapter.js +149 -0
  70. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +89 -0
  71. package/lib/model/strategy/adapter/dataVariant/evaluator.js +583 -0
  72. package/lib/model/strategy/adapter/dataVariant/examples.d.ts +39 -0
  73. package/lib/model/strategy/adapter/dataVariant/examples.js +293 -0
  74. package/lib/model/strategy/adapter/dataVariant/index.d.ts +4 -0
  75. package/lib/model/strategy/adapter/dataVariant/index.js +38 -0
  76. package/lib/model/strategy/adapter/dataVariant/type.d.ts +148 -0
  77. package/lib/model/strategy/adapter/dataVariant/type.js +31 -0
  78. package/lib/model/strategy/adapter/index.d.ts +4 -0
  79. package/lib/model/strategy/adapter/index.js +13 -2
  80. package/lib/model/strategy/adapter/promotion/adapter.d.ts +0 -4
  81. package/lib/model/strategy/adapter/promotion/adapter.js +0 -20
  82. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -17
  83. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -235
  84. package/lib/model/strategy/adapter/promotion/examples.d.ts +0 -86
  85. package/lib/model/strategy/adapter/promotion/examples.js +0 -91
  86. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  87. package/lib/model/strategy/adapter/promotion/index.js +0 -51
  88. package/lib/model/strategy/adapter/promotion/type.d.ts +2 -90
  89. package/lib/model/strategy/adapter/promotion/type.js +0 -2
  90. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -0
  91. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +1 -0
  92. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +1 -1
  93. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +23 -2
  94. package/lib/modules/Discount/index.d.ts +5 -2
  95. package/lib/modules/Discount/index.js +23 -3
  96. package/lib/modules/Discount/types.d.ts +4 -0
  97. package/lib/modules/Order/index.d.ts +14 -2
  98. package/lib/modules/Order/index.js +326 -60
  99. package/lib/modules/Order/types.d.ts +16 -0
  100. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  101. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  102. package/lib/modules/Order/utils.d.ts +4 -3
  103. package/lib/modules/Order/utils.js +22 -23
  104. package/lib/modules/Product/types.d.ts +22 -0
  105. package/lib/modules/ProductList/index.d.ts +1 -1
  106. package/lib/modules/ProductList/index.js +4 -2
  107. package/lib/modules/ProductList/types.d.ts +2 -0
  108. package/lib/modules/Rules/index.d.ts +2 -9
  109. package/lib/modules/Rules/index.js +61 -29
  110. package/lib/modules/Rules/types.d.ts +10 -1
  111. package/lib/server/index.d.ts +55 -0
  112. package/lib/server/index.js +327 -31
  113. package/lib/server/modules/order/index.d.ts +10 -4
  114. package/lib/server/modules/order/index.js +198 -139
  115. package/lib/server/modules/order/types.d.ts +4 -0
  116. package/lib/server/modules/products/index.d.ts +31 -8
  117. package/lib/server/modules/products/index.js +134 -35
  118. package/lib/server/modules/products/types.d.ts +18 -0
  119. package/lib/solution/BaseSales/index.d.ts +21 -1
  120. package/lib/solution/BaseSales/index.js +313 -72
  121. package/lib/solution/BaseSales/types.d.ts +6 -1
  122. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +1 -3
  123. package/lib/solution/BaseSales/utils/cartPromotion.js +29 -60
  124. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +3 -3
  125. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  126. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +8 -0
  127. package/lib/solution/BookingByStep/index.d.ts +1 -1
  128. package/lib/solution/BookingTicket/index.d.ts +1 -1
  129. package/lib/solution/BookingTicket/index.js +33 -8
  130. package/lib/solution/BookingTicket/types.d.ts +2 -0
  131. package/lib/solution/ScanOrder/index.js +0 -8
  132. package/lib/solution/ShopDiscount/index.js +2 -1
  133. package/lib/solution/VenueBooking/index.js +0 -8
  134. package/package.json +1 -1
@@ -198,6 +198,7 @@ export interface OrderProduct extends OrderProductIdentity {
198
198
  product_bundle: any[];
199
199
  booking_uid?: string;
200
200
  product_title?: OrderLocalizedText;
201
+ product_cover?: string;
201
202
  metadata: Record<string, any>;
202
203
  note?: string;
203
204
  }
@@ -308,6 +309,7 @@ export interface OrderState {
308
309
  lastOrderInfo?: Record<string, any>;
309
310
  syncState?: OrderSyncState;
310
311
  discountList: any[];
312
+ availableWalletIds?: number[];
311
313
  discount: DiscountModule | null;
312
314
  rules: RulesModule | null;
313
315
  }
@@ -340,6 +342,19 @@ export interface UpdateOrderProductParams {
340
342
  * });
341
343
  */
342
344
  allow_booking_reprice?: boolean;
345
+ /**
346
+ * Change time 重报价后,允许当前预约商品行重新应用已选编辑态折扣卡。
347
+ *
348
+ * @example
349
+ * await order.updateOrderProduct({
350
+ * product_id: 1,
351
+ * product_variant_id: 0,
352
+ * updates: { discount_list: [] },
353
+ * booking: { duration: 2 },
354
+ * allow_booking_discount_reapply: true,
355
+ * });
356
+ */
357
+ allow_booking_discount_reapply?: boolean;
343
358
  }
344
359
  /** 仅更新购物车行数量;行定位语义与 updateOrderProduct / removeProductFromOrder 保持一致 */
345
360
  export interface UpdateOrderProductQuantityParams extends OrderProductIdentity {
@@ -761,6 +776,7 @@ export interface OrderModuleAPI {
761
776
  apply?: boolean;
762
777
  }) => Promise<Discount[]>;
763
778
  getDiscountList: () => Discount[];
779
+ getAvailableWalletIds: () => number[];
764
780
  applyDiscount: () => void;
765
781
  /**
766
782
  * 注入促销评估器。
@@ -0,0 +1,53 @@
1
+ export type OrderCollectionKind = 'product' | 'booking' | 'payment';
2
+ export interface OrderCollectionIdentityStats {
3
+ backfilledUidCount: number;
4
+ collapsedDuplicateCount: number;
5
+ uidConflictCount: number;
6
+ anonymousRowCount: number;
7
+ }
8
+ export interface OrderCollectionUidRemap {
9
+ kind: OrderCollectionKind;
10
+ from: string;
11
+ to: string;
12
+ persistentId: string | null;
13
+ /** 默认全局迁移;UID 冲突时只能迁移能由另一侧 UID 明确定位的引用。 */
14
+ scope?: 'global' | 'linked-owner';
15
+ referenceOwnerUid?: string | null;
16
+ }
17
+ export interface NormalizeOrderCollectionResult<T> {
18
+ items: T[];
19
+ stats: OrderCollectionIdentityStats;
20
+ uidRemaps: OrderCollectionUidRemap[];
21
+ }
22
+ export interface NormalizeOrderCollectionsResult<T> {
23
+ order: T;
24
+ stats: Record<OrderCollectionKind, OrderCollectionIdentityStats>;
25
+ uidRemaps: OrderCollectionUidRemap[];
26
+ }
27
+ export declare function createUuidV4(): string;
28
+ export declare function isBlankOrderCollectionIdentity(value: unknown): boolean;
29
+ export declare function getOrderCollectionPersistentId(kind: OrderCollectionKind, item: unknown): string | null;
30
+ export declare function getOrderCollectionUid(kind: OrderCollectionKind, item: unknown): string | null;
31
+ export declare function buildOrderCollectionFallbackUid(kind: OrderCollectionKind, persistentId: string | number): string;
32
+ export declare function getOrderCollectionReferenceUid(kind: OrderCollectionKind, item: unknown): string | null;
33
+ export declare function setOrderCollectionUid<T>(kind: OrderCollectionKind, item: T, uid: string): T;
34
+ /**
35
+ * 持久化行 ID 是服务端事实主键;只有至少一侧尚未持久化时,才允许用 runtime UID 对齐。
36
+ */
37
+ export declare function isSameOrderCollectionItem(kind: OrderCollectionKind, left: unknown, right: unknown): boolean;
38
+ export declare function mergeOrderCollectionItems<T>(kind: OrderCollectionKind, currentItem: T, incomingItem: T, options?: {
39
+ ensureUid?: boolean;
40
+ createAnonymousUid?: () => string;
41
+ }): T;
42
+ /**
43
+ * 规范化单一数组:强身份重复时保留首次位置、用最后一条业务字段覆盖,并统一补 UID。
44
+ */
45
+ export declare function normalizeOrderCollection<T>(kind: OrderCollectionKind, items: T[] | null | undefined, options?: {
46
+ ensureUid?: boolean;
47
+ createAnonymousUid?: () => string;
48
+ }): NormalizeOrderCollectionResult<T>;
49
+ export declare function applyOrderCollectionUidRemaps<T extends Record<string, any>>(sourceOrder: T, uidRemaps: OrderCollectionUidRemap[]): T;
50
+ export declare function normalizeOrderCollections<T extends Record<string, any>>(sourceOrder: T, options?: {
51
+ ensureUid?: boolean;
52
+ createAnonymousUid?: () => string;
53
+ }): NormalizeOrderCollectionsResult<T>;
@@ -0,0 +1,405 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
6
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
+ import { cloneDeep } from 'lodash-es';
15
+ var IDENTITY_CONFIG = {
16
+ product: {
17
+ persistentIdField: 'order_detail_id',
18
+ uidField: 'unique_identification_number',
19
+ fallbackPrefix: 'os-fallback:product:order-detail'
20
+ },
21
+ booking: {
22
+ persistentIdField: 'schedule_event_id',
23
+ uidField: 'unique_identification_number',
24
+ fallbackPrefix: 'os-fallback:booking:schedule-event'
25
+ },
26
+ payment: {
27
+ persistentIdField: 'order_payment_id',
28
+ uidField: 'unique_payment_number',
29
+ fallbackPrefix: 'os-fallback:payment:order-payment'
30
+ }
31
+ };
32
+ export function createUuidV4() {
33
+ var template = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
34
+ return template.replace(/[xy]/g, function (char) {
35
+ var randomValue = Math.floor(Math.random() * 16);
36
+ var value = char === 'x' ? randomValue : randomValue & 0x3 | 0x8;
37
+ return value.toString(16);
38
+ });
39
+ }
40
+ export function isBlankOrderCollectionIdentity(value) {
41
+ return value === undefined || value === null || value === '';
42
+ }
43
+ export function getOrderCollectionPersistentId(kind, item) {
44
+ var record = item;
45
+ if (!record) return null;
46
+ var value = record[IDENTITY_CONFIG[kind].persistentIdField];
47
+ if (isBlankOrderCollectionIdentity(value)) return null;
48
+ return String(value);
49
+ }
50
+ export function getOrderCollectionUid(kind, item) {
51
+ var _record$metadata;
52
+ var record = item;
53
+ if (!record) return null;
54
+ var uidField = IDENTITY_CONFIG[kind].uidField;
55
+ var metadataValue = (_record$metadata = record.metadata) === null || _record$metadata === void 0 ? void 0 : _record$metadata[uidField];
56
+ if (!isBlankOrderCollectionIdentity(metadataValue)) return String(metadataValue);
57
+ var topLevelValue = record[uidField];
58
+ if (isBlankOrderCollectionIdentity(topLevelValue)) return null;
59
+ return String(topLevelValue);
60
+ }
61
+ export function buildOrderCollectionFallbackUid(kind, persistentId) {
62
+ return "".concat(IDENTITY_CONFIG[kind].fallbackPrefix, ":").concat(String(persistentId));
63
+ }
64
+ export function getOrderCollectionReferenceUid(kind, item) {
65
+ var uid = getOrderCollectionUid(kind, item);
66
+ if (uid) return uid;
67
+ var persistentId = getOrderCollectionPersistentId(kind, item);
68
+ return persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : null;
69
+ }
70
+ export function setOrderCollectionUid(kind, item, uid) {
71
+ var record = cloneDeep(item || {});
72
+ var uidField = IDENTITY_CONFIG[kind].uidField;
73
+ record.metadata = _objectSpread(_objectSpread({}, record.metadata && _typeof(record.metadata) === 'object' ? record.metadata : {}), {}, _defineProperty({}, uidField, uid));
74
+ delete record[uidField];
75
+ return record;
76
+ }
77
+
78
+ /**
79
+ * 持久化行 ID 是服务端事实主键;只有至少一侧尚未持久化时,才允许用 runtime UID 对齐。
80
+ */
81
+ export function isSameOrderCollectionItem(kind, left, right) {
82
+ var leftPersistentId = getOrderCollectionPersistentId(kind, left);
83
+ var rightPersistentId = getOrderCollectionPersistentId(kind, right);
84
+ if (leftPersistentId && rightPersistentId) {
85
+ return leftPersistentId === rightPersistentId;
86
+ }
87
+ var leftUid = getOrderCollectionUid(kind, left);
88
+ var rightUid = getOrderCollectionUid(kind, right);
89
+ return Boolean(leftUid && rightUid && leftUid === rightUid);
90
+ }
91
+ export function mergeOrderCollectionItems(kind, currentItem, incomingItem, options) {
92
+ var _options$createAnonym;
93
+ var current = cloneDeep(currentItem || {});
94
+ var incoming = cloneDeep(incomingItem || {});
95
+ var persistentIdField = IDENTITY_CONFIG[kind].persistentIdField;
96
+ var currentPersistentIdValue = current[persistentIdField];
97
+ var incomingPersistentIdValue = incoming[persistentIdField];
98
+ var incomingUid = getOrderCollectionUid(kind, incoming);
99
+ var currentUid = getOrderCollectionUid(kind, current);
100
+ var persistentId = getOrderCollectionPersistentId(kind, incoming) || getOrderCollectionPersistentId(kind, current);
101
+ var merged = _objectSpread(_objectSpread(_objectSpread({}, current), incoming), {}, {
102
+ metadata: _objectSpread(_objectSpread({}, current.metadata && _typeof(current.metadata) === 'object' ? current.metadata : {}), incoming.metadata && _typeof(incoming.metadata) === 'object' ? incoming.metadata : {})
103
+ });
104
+
105
+ // UID 对齐允许一侧尚未持久化,但稀疏 incoming 的 null/空值不能擦掉已存在行 ID。
106
+ if (!isBlankOrderCollectionIdentity(incomingPersistentIdValue)) {
107
+ merged[persistentIdField] = incomingPersistentIdValue;
108
+ } else if (!isBlankOrderCollectionIdentity(currentPersistentIdValue)) {
109
+ merged[persistentIdField] = currentPersistentIdValue;
110
+ }
111
+ var incomingUidIsDerived = Boolean(incomingUid && persistentId && (incomingUid === buildOrderCollectionFallbackUid(kind, persistentId) || incomingUid.startsWith("".concat(buildOrderCollectionFallbackUid(kind, persistentId), ":conflict:"))));
112
+ var uid = (incomingUid && !incomingUidIsDerived ? incomingUid : null) || currentUid || incomingUid || ((options === null || options === void 0 ? void 0 : options.ensureUid) === false ? null : persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : (options === null || options === void 0 || (_options$createAnonym = options.createAnonymousUid) === null || _options$createAnonym === void 0 ? void 0 : _options$createAnonym.call(options)) || createUuidV4());
113
+ return uid ? setOrderCollectionUid(kind, merged, uid) : merged;
114
+ }
115
+ function createEmptyIdentityStats() {
116
+ return {
117
+ backfilledUidCount: 0,
118
+ collapsedDuplicateCount: 0,
119
+ uidConflictCount: 0,
120
+ anonymousRowCount: 0
121
+ };
122
+ }
123
+ function allocateAnonymousUid(occupiedUids, createAnonymousUid) {
124
+ var uid = createAnonymousUid();
125
+ while (occupiedUids.has(uid)) uid = createAnonymousUid();
126
+ return uid;
127
+ }
128
+ function allocatePersistentConflictUid(kind, persistentId, occupiedUids) {
129
+ var fallbackUid = buildOrderCollectionFallbackUid(kind, persistentId);
130
+ if (!occupiedUids.has(fallbackUid)) return fallbackUid;
131
+
132
+ // 极端情况下其它行可能把本行 fallback 当作显式 UID 使用;继续派生稳定后缀,
133
+ // 避免修复冲突后仍留下重复 UID。规范化结果一旦持久化,后续读取保持幂等。
134
+ var suffix = 1;
135
+ var candidate = "".concat(fallbackUid, ":conflict:").concat(suffix);
136
+ while (occupiedUids.has(candidate)) {
137
+ suffix += 1;
138
+ candidate = "".concat(fallbackUid, ":conflict:").concat(suffix);
139
+ }
140
+ return candidate;
141
+ }
142
+
143
+ /**
144
+ * 规范化单一数组:强身份重复时保留首次位置、用最后一条业务字段覆盖,并统一补 UID。
145
+ */
146
+ export function normalizeOrderCollection(kind, items, options) {
147
+ var stats = createEmptyIdentityStats();
148
+ var uidRemaps = [];
149
+ var result = [];
150
+ var ensureUid = (options === null || options === void 0 ? void 0 : options.ensureUid) !== false;
151
+ var createAnonymousUid = (options === null || options === void 0 ? void 0 : options.createAnonymousUid) || createUuidV4;
152
+ var _iterator = _createForOfIteratorHelper(items || []),
153
+ _step;
154
+ try {
155
+ var _loop = function _loop() {
156
+ var rawItem = _step.value;
157
+ var item = cloneDeep(rawItem);
158
+ var existingIndex = result.findIndex(function (existing) {
159
+ return isSameOrderCollectionItem(kind, existing, item);
160
+ });
161
+ if (existingIndex === -1) {
162
+ result.push(item);
163
+ return 1; // continue
164
+ }
165
+ var previousReferenceUid = getOrderCollectionReferenceUid(kind, result[existingIndex]);
166
+ var incomingReferenceUid = getOrderCollectionReferenceUid(kind, item);
167
+ result[existingIndex] = mergeOrderCollectionItems(kind, result[existingIndex], item, {
168
+ ensureUid: false
169
+ });
170
+ var nextUid = getOrderCollectionUid(kind, result[existingIndex]);
171
+ if (nextUid) {
172
+ var _iterator2 = _createForOfIteratorHelper(new Set([previousReferenceUid, incomingReferenceUid])),
173
+ _step2;
174
+ try {
175
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
176
+ var from = _step2.value;
177
+ if (!from || from === nextUid) continue;
178
+ uidRemaps.push({
179
+ kind: kind,
180
+ from: from,
181
+ to: nextUid,
182
+ persistentId: getOrderCollectionPersistentId(kind, result[existingIndex])
183
+ });
184
+ }
185
+ } catch (err) {
186
+ _iterator2.e(err);
187
+ } finally {
188
+ _iterator2.f();
189
+ }
190
+ }
191
+ stats.collapsedDuplicateCount += 1;
192
+ };
193
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
194
+ if (_loop()) continue;
195
+ }
196
+ } catch (err) {
197
+ _iterator.e(err);
198
+ } finally {
199
+ _iterator.f();
200
+ }
201
+ if (!ensureUid) return {
202
+ items: result,
203
+ stats: stats,
204
+ uidRemaps: uidRemaps
205
+ };
206
+ var occupiedUids = new Set();
207
+ for (var index = 0; index < result.length; index += 1) {
208
+ var item = result[index];
209
+ var persistentId = getOrderCollectionPersistentId(kind, item);
210
+ var uid = getOrderCollectionUid(kind, item);
211
+ if (!uid) {
212
+ uid = persistentId ? buildOrderCollectionFallbackUid(kind, persistentId) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
213
+ item = setOrderCollectionUid(kind, item, uid);
214
+ result[index] = item;
215
+ stats.backfilledUidCount += 1;
216
+ if (!persistentId) stats.anonymousRowCount += 1;
217
+ }
218
+ if (occupiedUids.has(uid)) {
219
+ var _item, _item2, _item3, _item4;
220
+ var replacementUid = persistentId ? allocatePersistentConflictUid(kind, persistentId, occupiedUids) : allocateAnonymousUid(occupiedUids, createAnonymousUid);
221
+ result[index] = setOrderCollectionUid(kind, item, replacementUid);
222
+ uidRemaps.push({
223
+ kind: kind,
224
+ from: uid,
225
+ to: replacementUid,
226
+ persistentId: persistentId,
227
+ scope: 'linked-owner',
228
+ referenceOwnerUid: kind === 'product' ? String(((_item = item) === null || _item === void 0 ? void 0 : _item.booking_uid) || ((_item2 = item) === null || _item2 === void 0 || (_item2 = _item2.metadata) === null || _item2 === void 0 ? void 0 : _item2.booking_uid) || '') || null : kind === 'booking' ? String(((_item3 = item) === null || _item3 === void 0 ? void 0 : _item3.product_uid) || ((_item4 = item) === null || _item4 === void 0 || (_item4 = _item4.metadata) === null || _item4 === void 0 ? void 0 : _item4.product_uid) || '') || null : null
229
+ });
230
+ uid = replacementUid;
231
+ stats.uidConflictCount += 1;
232
+ }
233
+ occupiedUids.add(uid);
234
+ }
235
+ return {
236
+ items: result,
237
+ stats: stats,
238
+ uidRemaps: uidRemaps
239
+ };
240
+ }
241
+ export function applyOrderCollectionUidRemaps(sourceOrder, uidRemaps) {
242
+ if (!uidRemaps.length) return sourceOrder;
243
+ var order = cloneDeep(sourceOrder);
244
+ var hasAmbiguousLinkedOwner = function hasAmbiguousLinkedOwner(remap) {
245
+ if (remap.scope !== 'linked-owner' || !remap.referenceOwnerUid) return false;
246
+ var ownerKind = remap.kind === 'product' ? 'booking' : remap.kind === 'booking' ? 'product' : null;
247
+ if (!ownerKind) return false;
248
+ return uidRemaps.some(function (candidate) {
249
+ return candidate.scope === 'linked-owner' && candidate.kind === ownerKind && candidate.from === remap.referenceOwnerUid;
250
+ });
251
+ };
252
+ var _iterator3 = _createForOfIteratorHelper(uidRemaps),
253
+ _step3;
254
+ try {
255
+ var _loop2 = function _loop2() {
256
+ var remap = _step3.value;
257
+ if (remap.from === remap.to) return 0; // continue
258
+ var linkedOwnerIsAmbiguous = hasAmbiguousLinkedOwner(remap);
259
+ if (remap.kind === 'product') {
260
+ var _order$_extend;
261
+ var _iterator4 = _createForOfIteratorHelper(order.bookings || []),
262
+ _step4;
263
+ try {
264
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
265
+ var _booking$metadata;
266
+ var booking = _step4.value;
267
+ if (remap.scope === 'linked-owner' && (linkedOwnerIsAmbiguous || getOrderCollectionUid('booking', booking) !== remap.referenceOwnerUid)) {
268
+ continue;
269
+ }
270
+ if (String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === remap.from) {
271
+ booking.product_uid = remap.to;
272
+ }
273
+ if (String((booking === null || booking === void 0 || (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.product_uid) || '') === remap.from) {
274
+ booking.metadata = _objectSpread(_objectSpread({}, booking.metadata || {}), {}, {
275
+ product_uid: remap.to
276
+ });
277
+ }
278
+ }
279
+ // 冲突 UID 仍由第一条持有;赠品父引用缺少可用的持久化行定位时不能全局改写。
280
+ } catch (err) {
281
+ _iterator4.e(err);
282
+ } finally {
283
+ _iterator4.f();
284
+ }
285
+ if (remap.scope !== 'linked-owner') {
286
+ var _iterator5 = _createForOfIteratorHelper(order.products || []),
287
+ _step5;
288
+ try {
289
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
290
+ var _product$metadata, _product$metadata2;
291
+ var product = _step5.value;
292
+ if (String((product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.parent_unique_identification_number) || '') === remap.from) {
293
+ product.metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
294
+ parent_unique_identification_number: remap.to
295
+ });
296
+ }
297
+ var giftInfo = product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2._giftInfo;
298
+ if (giftInfo && _typeof(giftInfo) === 'object') {
299
+ var sourceProductIds = Array.isArray(giftInfo.sourceProductIds) ? giftInfo.sourceProductIds.map(function (uid) {
300
+ return String(uid) === remap.from ? remap.to : uid;
301
+ }) : giftInfo.sourceProductIds;
302
+ var sourceProductId = String(giftInfo.sourceProductId || '') === remap.from ? remap.to : giftInfo.sourceProductId;
303
+ product.metadata = _objectSpread(_objectSpread({}, product.metadata || {}), {}, {
304
+ _giftInfo: _objectSpread(_objectSpread(_objectSpread({}, giftInfo), sourceProductIds !== undefined ? {
305
+ sourceProductIds: sourceProductIds
306
+ } : {}), sourceProductId !== undefined ? {
307
+ sourceProductId: sourceProductId
308
+ } : {})
309
+ });
310
+ }
311
+ }
312
+ } catch (err) {
313
+ _iterator5.e(err);
314
+ } finally {
315
+ _iterator5.f();
316
+ }
317
+ }
318
+ var productsByUid = (_order$_extend = order._extend) === null || _order$_extend === void 0 ? void 0 : _order$_extend.productsByUid;
319
+ var cachedProduct = productsByUid === null || productsByUid === void 0 ? void 0 : productsByUid[remap.from];
320
+ var cachedPersistentId = getOrderCollectionPersistentId('product', (cachedProduct === null || cachedProduct === void 0 ? void 0 : cachedProduct.origin) || cachedProduct);
321
+ if (productsByUid && remap.scope === 'linked-owner') {
322
+ var retainedProduct = (order.products || []).find(function (product) {
323
+ return getOrderCollectionUid('product', product) === remap.from;
324
+ });
325
+ var remappedProduct = (order.products || []).find(function (product) {
326
+ return getOrderCollectionUid('product', product) === remap.to;
327
+ });
328
+ if (cachedProduct && remap.persistentId && cachedPersistentId === remap.persistentId) {
329
+ productsByUid[remap.to] = _objectSpread(_objectSpread({}, cachedProduct || {}), productsByUid[remap.to] || {});
330
+ if (retainedProduct) {
331
+ productsByUid[remap.from] = _objectSpread(_objectSpread({}, cachedProduct || {}), {}, {
332
+ origin: cloneDeep(retainedProduct)
333
+ });
334
+ }
335
+ } else if (remappedProduct && !productsByUid[remap.to]) {
336
+ productsByUid[remap.to] = {
337
+ origin: cloneDeep(remappedProduct)
338
+ };
339
+ }
340
+ return 0; // continue
341
+ }
342
+ if (cachedProduct && remap.scope !== 'linked-owner') {
343
+ productsByUid[remap.to] = _objectSpread(_objectSpread({}, cachedProduct || {}), productsByUid[remap.to] || {});
344
+ delete productsByUid[remap.from];
345
+ }
346
+ }
347
+ if (remap.kind === 'booking') {
348
+ var _iterator6 = _createForOfIteratorHelper(order.products || []),
349
+ _step6;
350
+ try {
351
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
352
+ var _product$metadata3;
353
+ var _product = _step6.value;
354
+ if (remap.scope === 'linked-owner' && (linkedOwnerIsAmbiguous || getOrderCollectionUid('product', _product) !== remap.referenceOwnerUid)) {
355
+ continue;
356
+ }
357
+ if (String((_product === null || _product === void 0 ? void 0 : _product.booking_uid) || '') === remap.from) {
358
+ _product.booking_uid = remap.to;
359
+ }
360
+ if (String((_product === null || _product === void 0 || (_product$metadata3 = _product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.booking_uid) || '') === remap.from) {
361
+ _product.metadata = _objectSpread(_objectSpread({}, _product.metadata || {}), {}, {
362
+ booking_uid: remap.to
363
+ });
364
+ }
365
+ }
366
+ } catch (err) {
367
+ _iterator6.e(err);
368
+ } finally {
369
+ _iterator6.f();
370
+ }
371
+ }
372
+ },
373
+ _ret;
374
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
375
+ _ret = _loop2();
376
+ if (_ret === 0) continue;
377
+ }
378
+ } catch (err) {
379
+ _iterator3.e(err);
380
+ } finally {
381
+ _iterator3.f();
382
+ }
383
+ return order;
384
+ }
385
+ export function normalizeOrderCollections(sourceOrder, options) {
386
+ var order = cloneDeep(sourceOrder || {});
387
+ var orderRecord = order;
388
+ var productResult = normalizeOrderCollection('product', Array.isArray(orderRecord.products) ? orderRecord.products : [], options);
389
+ var bookingResult = normalizeOrderCollection('booking', Array.isArray(orderRecord.bookings) ? orderRecord.bookings : [], options);
390
+ var paymentResult = normalizeOrderCollection('payment', Array.isArray(orderRecord.payments) ? orderRecord.payments : [], options);
391
+ if (Array.isArray(orderRecord.products)) orderRecord.products = productResult.items;
392
+ if (Array.isArray(orderRecord.bookings)) orderRecord.bookings = bookingResult.items;
393
+ if (Array.isArray(orderRecord.payments)) orderRecord.payments = paymentResult.items;
394
+ var uidRemaps = [].concat(_toConsumableArray(productResult.uidRemaps), _toConsumableArray(bookingResult.uidRemaps), _toConsumableArray(paymentResult.uidRemaps));
395
+ order = applyOrderCollectionUidRemaps(order, uidRemaps);
396
+ return {
397
+ order: order,
398
+ stats: {
399
+ product: productResult.stats,
400
+ booking: bookingResult.stats,
401
+ payment: paymentResult.stats
402
+ },
403
+ uidRemaps: uidRemaps
404
+ };
405
+ }
@@ -3,6 +3,7 @@ import type { CartItem } from "../Cart";
3
3
  import type { OrderProductDiscountItem, OrderProduct, OrderSubmitPayload, OrderSubmitProduct, OrderSummary, OrderTempOrder } from './types';
4
4
  import type { RulesParamsHooks } from '../Rules/types';
5
5
  import type { MapOrderPaymentsOptions, OrderPaymentData, OrderPaymentSource } from './types';
6
+ import { createUuidV4 } from './utils/orderCollectionIdentity';
6
7
  export interface OrderProductsDepositProtocol {
7
8
  id: number;
8
9
  title: string;
@@ -67,8 +68,8 @@ export declare function sumOptionUnitPrice(options?: Array<{
67
68
  /**
68
69
  * 仅基于 tempOrder.products 重算整单定金。
69
70
  *
70
- * 对齐 Checkout relation_products 分支:商品定金先按商品规则计算,
71
- * 再扣减商品券/折扣卡抵扣金额;tempOrder.bookings 不参与这里的计算。
71
+ * 商品折扣在进入定金计算前已体现在商品行价格字段中,
72
+ * 因此这里只按商品定金规则汇总,不再扣减 discount_list;tempOrder.bookings 不参与这里的计算。
72
73
  */
73
74
  export declare function calculateOrderProductsDeposit(products?: OrderProduct[], options?: {
74
75
  productsByUid?: Record<string, Record<string, any>>;
@@ -177,7 +178,7 @@ export declare const mergeRelationForms: (relationForms: {
177
178
  form_record_ids: number[];
178
179
  }[];
179
180
  export declare const getAllDiscountList: (cartItem: CartItem) => any;
180
- export declare function createUuidV4(): string;
181
+ export { createUuidV4 };
181
182
  export declare function isTempOrder(data: any): data is OrderTempOrder;
182
183
  export declare function formatDateTime(date: Date): string;
183
184
  export declare function normalizeBookingIsAll(booking: Record<string, any>): 0 | 1;