@pisell/pisellos 2.2.171 → 2.2.172

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 (156) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +193 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +137 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +215 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.d.ts +6 -0
  32. package/dist/modules/Customer/index.js +129 -83
  33. package/dist/modules/Customer/types.d.ts +2 -0
  34. package/dist/modules/Discount/index.d.ts +2 -4
  35. package/dist/modules/Discount/index.js +8 -93
  36. package/dist/modules/Discount/types.d.ts +1 -7
  37. package/dist/modules/Order/index.d.ts +47 -16
  38. package/dist/modules/Order/index.js +743 -334
  39. package/dist/modules/Order/types.d.ts +57 -17
  40. package/dist/modules/Order/types.js +2 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  42. package/dist/modules/Order/utils/manualProductDiscount.js +212 -0
  43. package/dist/modules/Order/utils.d.ts +23 -1
  44. package/dist/modules/Order/utils.js +139 -30
  45. package/dist/modules/Quotation/index.js +16 -5
  46. package/dist/modules/Rules/index.d.ts +4 -0
  47. package/dist/modules/Rules/index.js +26 -10
  48. package/dist/modules/SalesSummary/index.js +4 -2
  49. package/dist/modules/Schedule/index.js +6 -2
  50. package/dist/modules/index.d.ts +1 -0
  51. package/dist/modules/index.js +2 -1
  52. package/dist/server/index.js +10 -6
  53. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  54. package/dist/server/modules/products/index.js +9 -8
  55. package/dist/server/modules/schedule/index.js +13 -6
  56. package/dist/solution/BaseSales/index.d.ts +65 -7
  57. package/dist/solution/BaseSales/index.js +1066 -315
  58. package/dist/solution/BaseSales/types.d.ts +53 -1
  59. package/dist/solution/BaseSales/types.js +3 -1
  60. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  61. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  62. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +65 -15
  63. package/dist/solution/BaseSales/utils.js +46 -8
  64. package/dist/solution/BookingTicket/index.d.ts +134 -2
  65. package/dist/solution/BookingTicket/index.js +768 -175
  66. package/dist/solution/BookingTicket/types.d.ts +2 -0
  67. package/dist/solution/BookingTicket/types.js +3 -0
  68. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  69. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  70. package/dist/solution/ScanOrder/index.d.ts +9 -3
  71. package/dist/solution/ScanOrder/index.js +231 -128
  72. package/dist/solution/ScanOrder/utils.js +46 -8
  73. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  74. package/dist/solution/ShopDiscount/index.js +18 -23
  75. package/dist/solution/VenueBooking/index.d.ts +5 -9
  76. package/dist/solution/VenueBooking/index.js +103 -55
  77. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  78. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  79. package/lib/modules/BookingContext/index.d.ts +37 -0
  80. package/lib/modules/BookingContext/index.js +297 -0
  81. package/lib/modules/BookingContext/types.d.ts +102 -0
  82. package/lib/modules/BookingContext/types.js +34 -0
  83. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +207 -0
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  86. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  87. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  88. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  89. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  90. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  91. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  92. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  93. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  94. package/lib/modules/BookingContext/utils/index.js +43 -0
  95. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  96. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  97. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  98. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  99. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  100. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  101. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  102. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  103. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  104. package/lib/modules/BookingContext/utils/resources.js +377 -0
  105. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  106. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  107. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  108. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  109. package/lib/modules/Customer/index.d.ts +6 -0
  110. package/lib/modules/Customer/index.js +26 -11
  111. package/lib/modules/Customer/types.d.ts +2 -0
  112. package/lib/modules/Discount/index.d.ts +2 -4
  113. package/lib/modules/Discount/index.js +8 -63
  114. package/lib/modules/Discount/types.d.ts +1 -7
  115. package/lib/modules/Order/index.d.ts +47 -16
  116. package/lib/modules/Order/index.js +389 -90
  117. package/lib/modules/Order/types.d.ts +57 -17
  118. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  119. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  120. package/lib/modules/Order/utils.d.ts +23 -1
  121. package/lib/modules/Order/utils.js +145 -21
  122. package/lib/modules/Quotation/index.js +17 -6
  123. package/lib/modules/Rules/index.d.ts +4 -0
  124. package/lib/modules/Rules/index.js +22 -14
  125. package/lib/modules/SalesSummary/index.js +4 -2
  126. package/lib/modules/Schedule/index.js +3 -1
  127. package/lib/modules/index.d.ts +1 -0
  128. package/lib/modules/index.js +3 -1
  129. package/lib/server/index.js +2 -0
  130. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  131. package/lib/server/modules/products/index.js +8 -9
  132. package/lib/server/modules/schedule/index.js +2 -1
  133. package/lib/solution/BaseSales/index.d.ts +65 -7
  134. package/lib/solution/BaseSales/index.js +492 -20
  135. package/lib/solution/BaseSales/types.d.ts +53 -1
  136. package/lib/solution/BaseSales/types.js +3 -1
  137. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  138. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  139. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +70 -11
  140. package/lib/solution/BaseSales/utils.js +46 -6
  141. package/lib/solution/BookingTicket/index.d.ts +134 -2
  142. package/lib/solution/BookingTicket/index.js +341 -8
  143. package/lib/solution/BookingTicket/types.d.ts +2 -0
  144. package/lib/solution/BookingTicket/types.js +6 -0
  145. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  146. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  147. package/lib/solution/ScanOrder/index.d.ts +9 -3
  148. package/lib/solution/ScanOrder/index.js +147 -66
  149. package/lib/solution/ScanOrder/utils.js +46 -6
  150. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  151. package/lib/solution/ShopDiscount/index.js +2 -4
  152. package/lib/solution/VenueBooking/index.d.ts +5 -9
  153. package/lib/solution/VenueBooking/index.js +50 -14
  154. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  155. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  156. package/package.json +2 -2
@@ -0,0 +1,193 @@
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 _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); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ 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; }
7
+ 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); }
8
+ 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; }
9
+ 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; }
10
+ 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; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ 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); }
13
+ import dayjs from 'dayjs';
14
+ import { resolveManualDiscountMessage } from "../../Order/utils/manualProductDiscount";
15
+ function safeFormat(value, fmt) {
16
+ if (value === undefined || value === null) return undefined;
17
+ var d = dayjs(value);
18
+ if (!d.isValid()) return undefined;
19
+ return d.format(fmt);
20
+ }
21
+ function normalizeTimeString(value) {
22
+ if (value === undefined || value === null) return undefined;
23
+ if (typeof value === 'string') {
24
+ var t = value.trim();
25
+ var hhmmFromHhmmss = t.match(/^(\d{1,2}:\d{2}):\d{2}$/);
26
+ if (hhmmFromHhmmss) return hhmmFromHhmmss[1];
27
+ if (/^\d{1,2}:\d{2}$/.test(t)) return t;
28
+ }
29
+ var d = dayjs(value);
30
+ if (d.isValid()) return d.format('HH:mm');
31
+ return undefined;
32
+ }
33
+
34
+ /**
35
+ * bookings[].resources[] → cacheItem._extend.resource(与 cacheItemToBookingInput.flattenResources 互逆)。
36
+ */
37
+ function unflattenResourceMap(resources) {
38
+ var map = {};
39
+ if (!Array.isArray(resources)) return map;
40
+ resources.forEach(function (r) {
41
+ var formId = r === null || r === void 0 ? void 0 : r.form_id;
42
+ if (formId === undefined || formId === null) return;
43
+ var key = String(formId);
44
+ if (!map[key]) map[key] = [];
45
+ map[key].push({
46
+ form_id: formId,
47
+ relation_id: r.relation_id,
48
+ relation_type: r.relation_type || 'form',
49
+ like_status: r.like_status || 'common',
50
+ metadata: r.metadata ? _objectSpread({}, r.metadata) : undefined,
51
+ children: r.children
52
+ });
53
+ });
54
+ return map;
55
+ }
56
+
57
+ /**
58
+ * 从 booking.metadata.capacity 还原 `_extend.capacity`(与 info2 ticketBooking getCapacity 对齐)。
59
+ * 勿用 resources[].relation_id 反推人数维度 id。
60
+ */
61
+ function resolveCapacityFromBooking(booking) {
62
+ var _booking$metadata;
63
+ var metaCap = (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.capacity;
64
+ if (Array.isArray(metaCap) && metaCap.length > 0) {
65
+ return metaCap.map(function (item) {
66
+ var _item$value;
67
+ if (!item || _typeof(item) !== 'object') return null;
68
+ if (item.id === undefined || item.id === null) return null;
69
+ var row = {
70
+ id: item.id,
71
+ value: Number((_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : 0)
72
+ };
73
+ if (item.name !== undefined) row.name = item.name;
74
+ return row;
75
+ }).filter(function (item) {
76
+ return item != null;
77
+ });
78
+ }
79
+ if (typeof metaCap === 'number' && Number.isFinite(metaCap)) {
80
+ return [{
81
+ id: 0,
82
+ value: metaCap,
83
+ name: ''
84
+ }];
85
+ }
86
+ return [];
87
+ }
88
+ function resolveDurationForExtend(booking) {
89
+ var duration = booking.duration;
90
+ if (booking.sub_type === 'days' || booking.is_all === 1) {
91
+ return duration;
92
+ }
93
+ if (typeof duration === 'number' && Number.isFinite(duration)) {
94
+ return duration;
95
+ }
96
+ return duration;
97
+ }
98
+
99
+ /**
100
+ * 从已加车的 order line + booking 反查 editService 所需的 cacheItem。
101
+ *
102
+ * 与 `buildCacheItemFromCartDetail` / `buildCacheItemFromDetail` 正向拼装互逆(在 getProductExtend 之前调用)。
103
+ * 调用方须传入与该行关联的 booking(通常 bookings[].product_uid === product.metadata.unique_identification_number)。
104
+ */
105
+ export function buildCacheItemFromOrderLine(input) {
106
+ var _product$product_id, _product$selling_pric, _product$original_pri, _booking$metadata$hol, _booking$metadata2, _product$product_vari, _product$num, _ref, _ref2, _title, _booking$product, _booking$detail, _ref3, _product$note, _booking$detail2, _product$metadata, _product$metadata2, _ref4, _extension_type, _booking$product2, _title2, _booking$product3, _price, _product$order_detail, _ref5, _booking$id;
107
+ var product = input.product,
108
+ booking = input.booking,
109
+ sourceProduct = input.sourceProduct;
110
+ var resolvedId = (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id;
111
+ var selling = Number((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
112
+ var original = Number((_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : selling);
113
+ var startDate = safeFormat(booking.start_date, 'YYYY-MM-DD');
114
+ var endDate = safeFormat(booking.end_date, 'YYYY-MM-DD');
115
+ var startTime = normalizeTimeString(booking.start_time);
116
+ var endTime = normalizeTimeString(booking.end_time);
117
+ var resource = unflattenResourceMap(booking.resources);
118
+ var capacity = resolveCapacityFromBooking(booking);
119
+ var holderId = (_booking$metadata$hol = (_booking$metadata2 = booking.metadata) === null || _booking$metadata2 === void 0 ? void 0 : _booking$metadata2.holder_id) !== null && _booking$metadata$hol !== void 0 ? _booking$metadata$hol : booking.holder_id;
120
+ var other = {
121
+ product_variant_id: (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0,
122
+ option: Array.isArray(product.product_option_item) ? _toConsumableArray(product.product_option_item) : [],
123
+ bundle: Array.isArray(product.product_bundle) ? _toConsumableArray(product.product_bundle) : []
124
+ };
125
+ var extend = {
126
+ start_date: startDate ? dayjs(startDate) : undefined,
127
+ end_date: endDate ? dayjs(endDate) : undefined,
128
+ startDate: startDate ? dayjs(startDate) : undefined,
129
+ endDate: endDate ? dayjs(endDate) : undefined,
130
+ start_time: startTime,
131
+ end_time: endTime,
132
+ duration: resolveDurationForExtend(booking),
133
+ sub_type: booking.sub_type,
134
+ quantity: (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : 1,
135
+ product_name: (_ref = (_ref2 = (_title = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) !== null && _title !== void 0 ? _title : booking === null || booking === void 0 || (_booking$product = booking.product) === null || _booking$product === void 0 ? void 0 : _booking$product.title) !== null && _ref2 !== void 0 ? _ref2 : booking === null || booking === void 0 || (_booking$detail = booking.detail) === null || _booking$detail === void 0 ? void 0 : _booking$detail.product_title) !== null && _ref !== void 0 ? _ref : '',
136
+ note: (_ref3 = (_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : booking === null || booking === void 0 || (_booking$detail2 = booking.detail) === null || _booking$detail2 === void 0 ? void 0 : _booking$detail2.note) !== null && _ref3 !== void 0 ? _ref3 : '',
137
+ price: selling,
138
+ total: selling,
139
+ origin_total: original,
140
+ resource: resource,
141
+ capacity: capacity,
142
+ holder_id: holderId,
143
+ other: other,
144
+ like_status: booking.like_status || 'common',
145
+ discount_reason: resolveManualDiscountMessage(product.discount_list, (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.product_discount_reason) || undefined
146
+ };
147
+ var manualDiscount = (product.discount_list || []).find(function (d) {
148
+ return (d === null || d === void 0 ? void 0 : d.type) === 'product';
149
+ });
150
+ if (manualDiscount && extend.origin_total === selling) {
151
+ var _manualDiscount$amoun;
152
+ var manualAmount = Number((_manualDiscount$amoun = manualDiscount.amount) !== null && _manualDiscount$amoun !== void 0 ? _manualDiscount$amoun : 0);
153
+ if (Number.isFinite(manualAmount) && manualAmount > 0) {
154
+ extend.origin_total = selling + manualAmount;
155
+ }
156
+ }
157
+ if (((_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.price_override) != null || manualDiscount) {
158
+ extend.priceOverride = selling;
159
+ }
160
+ if (booking.holder !== undefined) {
161
+ extend.holder = booking.holder;
162
+ }
163
+ if (Array.isArray(booking.relation_forms)) {
164
+ extend.relation_forms = booking.relation_forms;
165
+ }
166
+ var base = _objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
167
+ id: resolvedId,
168
+ product_id: resolvedId,
169
+ extension_type: (_ref4 = (_extension_type = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type) !== null && _extension_type !== void 0 ? _extension_type : booking === null || booking === void 0 || (_booking$product2 = booking.product) === null || _booking$product2 === void 0 ? void 0 : _booking$product2.extension_type) !== null && _ref4 !== void 0 ? _ref4 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.extension_type,
170
+ title: (_title2 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) !== null && _title2 !== void 0 ? _title2 : booking === null || booking === void 0 || (_booking$product3 = booking.product) === null || _booking$product3 === void 0 ? void 0 : _booking$product3.title,
171
+ price: (_price = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price !== void 0 ? _price : selling,
172
+ selling_price: product.selling_price,
173
+ original_price: product.original_price,
174
+ _extend: extend,
175
+ new: 0,
176
+ autoClose: false,
177
+ order_detail_id: (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : null,
178
+ booking_id: (_ref5 = (_booking$id = booking.id) !== null && _booking$id !== void 0 ? _booking$id : booking.booking_id) !== null && _ref5 !== void 0 ? _ref5 : 0
179
+ });
180
+ if ((sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.capacity) !== undefined) {
181
+ base.capacity = sourceProduct.capacity;
182
+ }
183
+ if ((sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.duration) !== undefined) {
184
+ base.duration = sourceProduct.duration;
185
+ }
186
+ if ((sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_resource) !== undefined) {
187
+ base.product_resource = sourceProduct.product_resource;
188
+ }
189
+ if (booking.schedule_event_id !== undefined) {
190
+ base.schedule_event_id = booking.schedule_event_id;
191
+ }
192
+ return base;
193
+ }
@@ -0,0 +1,8 @@
1
+ import type { OrderProduct } from '../../Order/types';
2
+ export interface BuildNormalProductCacheItemFromOrderLineInput {
3
+ /** tempOrder.products 中的一行(普通商品,无关联 booking) */
4
+ product: OrderProduct;
5
+ /** 商品 catalog / 详情,用于 variant / option / bundle 模板字段 */
6
+ sourceProduct?: Record<string, any> | null;
7
+ }
8
+ export declare function buildNormalProductCacheItemFromOrderLine(input: BuildNormalProductCacheItemFromOrderLineInput): Record<string, any>;
@@ -0,0 +1,137 @@
1
+ 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); }
2
+ var _excluded = ["bundle_selling_price"];
3
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+ 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."); }
5
+ 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); }
6
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
+ 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; }
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
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
+ /**
17
+ * 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
18
+ *
19
+ * 与 `buildCacheItemFromOrderLine`(预约行 + booking)并列;不含 resource / duration / holder 等预约字段。
20
+ */
21
+ /**
22
+ * 解析 v2 主商品 source 价(不含 option、不含 bundle),供 SkuDetailModal / transform 使用。
23
+ */
24
+ function resolveSourceProductPrice(product, sourceProduct) {
25
+ var _price, _price2, _metadata$origin2, _metadata$origin3, _product$selling_pric;
26
+ var metadata = product.metadata || {};
27
+ if (metadata.source_product_price !== undefined && metadata.source_product_price !== null) {
28
+ var parsed = Number(metadata.source_product_price);
29
+ if (Number.isFinite(parsed)) return parsed;
30
+ }
31
+ var variantId = Number(product.product_variant_id || 0);
32
+ if (variantId > 0) {
33
+ var _variant, _metadata$origin;
34
+ var variantList = (_variant = (_metadata$origin = metadata.origin) === null || _metadata$origin === void 0 ? void 0 : _metadata$origin.variant) !== null && _variant !== void 0 ? _variant : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.variant;
35
+ if (Array.isArray(variantList)) {
36
+ var _matched$price;
37
+ var matched = variantList.find(function (v) {
38
+ return Number(v === null || v === void 0 ? void 0 : v.id) === variantId;
39
+ });
40
+ var variantPrice = (_matched$price = matched === null || matched === void 0 ? void 0 : matched.price) !== null && _matched$price !== void 0 ? _matched$price : matched === null || matched === void 0 ? void 0 : matched.base_price;
41
+ if (variantPrice !== undefined && variantPrice !== null) {
42
+ var _parsed = Number(variantPrice);
43
+ if (Number.isFinite(_parsed)) return _parsed;
44
+ }
45
+ }
46
+ }
47
+ var catalogPrice = (_price = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price !== void 0 ? _price : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price;
48
+ if (catalogPrice !== undefined && catalogPrice !== null) {
49
+ var _parsed2 = Number(catalogPrice);
50
+ if (Number.isFinite(_parsed2)) return _parsed2;
51
+ }
52
+ var originPrice = (_price2 = (_metadata$origin2 = metadata.origin) === null || _metadata$origin2 === void 0 ? void 0 : _metadata$origin2.price) !== null && _price2 !== void 0 ? _price2 : (_metadata$origin3 = metadata.origin) === null || _metadata$origin3 === void 0 ? void 0 : _metadata$origin3.base_price;
53
+ if (originPrice !== undefined && originPrice !== null) {
54
+ var _parsed3 = Number(originPrice);
55
+ if (Number.isFinite(_parsed3)) return _parsed3;
56
+ }
57
+ return Number((_product$selling_pric = product.selling_price) !== null && _product$selling_pric !== void 0 ? _product$selling_pric : 0);
58
+ }
59
+
60
+ /** 订单行 bundle → booking other.bundle(保留 original_price 供 setProductPrice 按比例分摊) */
61
+ function mapOrderBundleToOtherBundle(bundle) {
62
+ return bundle.map(function (item) {
63
+ var _ref, _ref2, _item$original_price, _ref3, _item$bundle_selling_, _item$original_total, _ref4, _item$num, _ref5, _item$quantity;
64
+ var catalogOriginal = (_ref = (_ref2 = (_item$original_price = item.original_price) !== null && _item$original_price !== void 0 ? _item$original_price : item.product_price) !== null && _ref2 !== void 0 ? _ref2 : item.price) !== null && _ref !== void 0 ? _ref : item.bundle_selling_price;
65
+ var selling = (_ref3 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref3 !== void 0 ? _ref3 : catalogOriginal;
66
+ var _omitBundleSelling = item.bundle_selling_price,
67
+ rest = _objectWithoutProperties(item, _excluded);
68
+ return _objectSpread(_objectSpread({}, rest), {}, {
69
+ price: selling,
70
+ original_price: catalogOriginal,
71
+ original_total: (_item$original_total = item.original_total) !== null && _item$original_total !== void 0 ? _item$original_total : catalogOriginal,
72
+ num: (_ref4 = (_item$num = item.num) !== null && _item$num !== void 0 ? _item$num : item.quantity) !== null && _ref4 !== void 0 ? _ref4 : 1,
73
+ quantity: (_ref5 = (_item$quantity = item.quantity) !== null && _item$quantity !== void 0 ? _item$quantity : item.num) !== null && _ref5 !== void 0 ? _ref5 : 1
74
+ });
75
+ });
76
+ }
77
+ export function buildNormalProductCacheItemFromOrderLine(input) {
78
+ var _product$product_id, _product$selling_pric2, _product$original_pri, _product$metadata, _product$metadata2, _product$product_vari, _originExtend$other, _product$num, _product$product_vari2, _product$num2, _title, _product$note, _originExtend$price, _originExtend$total, _originExtend$origin_, _price3, _product$order_detail;
79
+ var product = input.product,
80
+ sourceProduct = input.sourceProduct;
81
+ var resolvedId = (_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id;
82
+ var sourcePrice = resolveSourceProductPrice(product, sourceProduct);
83
+ var selling = Number((_product$selling_pric2 = product.selling_price) !== null && _product$selling_pric2 !== void 0 ? _product$selling_pric2 : 0);
84
+ var original = Number((_product$original_pri = product.original_price) !== null && _product$original_pri !== void 0 ? _product$original_pri : selling);
85
+ var uid = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number;
86
+ var option = Array.isArray(product.product_option_item) ? _toConsumableArray(product.product_option_item) : [];
87
+ var bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : []);
88
+ var originExtend = (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 || (_product$metadata2 = _product$metadata2.origin) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2._extend;
89
+ var other = {
90
+ product_id: resolvedId,
91
+ product_variant_id: (_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : 0,
92
+ option: option,
93
+ bundle: originExtend !== null && originExtend !== void 0 && (_originExtend$other = originExtend.other) !== null && _originExtend$other !== void 0 && _originExtend$other.bundle ? JSON.parse(JSON.stringify(originExtend.other.bundle)) : bundle,
94
+ quantity: (_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : 1
95
+ };
96
+ var skuValue = {
97
+ product_id: resolvedId,
98
+ product_variant_id: (_product$product_vari2 = product.product_variant_id) !== null && _product$product_vari2 !== void 0 ? _product$product_vari2 : 0,
99
+ option: other.option,
100
+ bundle: other.bundle
101
+ };
102
+ var extend = _objectSpread(_objectSpread({
103
+ quantity: (_product$num2 = product.num) !== null && _product$num2 !== void 0 ? _product$num2 : 1,
104
+ product_name: (_title = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title) !== null && _title !== void 0 ? _title : '',
105
+ note: (_product$note = product.note) !== null && _product$note !== void 0 ? _product$note : '',
106
+ // v2:_extend.price 为主商品 source 价;行 composite 用 total / origin_total 展示
107
+ price: (_originExtend$price = originExtend === null || originExtend === void 0 ? void 0 : originExtend.price) !== null && _originExtend$price !== void 0 ? _originExtend$price : sourcePrice,
108
+ total: (_originExtend$total = originExtend === null || originExtend === void 0 ? void 0 : originExtend.total) !== null && _originExtend$total !== void 0 ? _originExtend$total : selling,
109
+ origin_total: (_originExtend$origin_ = originExtend === null || originExtend === void 0 ? void 0 : originExtend.origin_total) !== null && _originExtend$origin_ !== void 0 ? _originExtend$origin_ : original,
110
+ other: other,
111
+ skuValue: JSON.parse(JSON.stringify(skuValue)),
112
+ _skuValue: JSON.parse(JSON.stringify(skuValue)),
113
+ isNormalProduct: true
114
+ }, (originExtend === null || originExtend === void 0 ? void 0 : originExtend.priceOverride) !== undefined ? {
115
+ priceOverride: originExtend.priceOverride
116
+ } : {}), (originExtend === null || originExtend === void 0 ? void 0 : originExtend.bundle_edit) !== undefined ? {
117
+ bundle_edit: originExtend.bundle_edit
118
+ } : {});
119
+ if (originExtend !== null && originExtend !== void 0 && originExtend.skuValue || originExtend !== null && originExtend !== void 0 && originExtend._skuValue) {
120
+ extend.skuValue = JSON.parse(JSON.stringify(originExtend.skuValue || originExtend._skuValue));
121
+ extend._skuValue = JSON.parse(JSON.stringify(extend.skuValue));
122
+ }
123
+ return _objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
124
+ id: resolvedId,
125
+ product_id: resolvedId,
126
+ _id: uid,
127
+ title: sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.title,
128
+ price: (_price3 = sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _price3 !== void 0 ? _price3 : sourcePrice,
129
+ selling_price: product.selling_price,
130
+ original_price: product.original_price,
131
+ note: product.note,
132
+ order_detail_id: (_product$order_detail = product.order_detail_id) !== null && _product$order_detail !== void 0 ? _product$order_detail : null,
133
+ new: 0,
134
+ autoClose: true,
135
+ _extend: extend
136
+ });
137
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * 把 info2 `cacheItem` 转换为 OS `addProductToOrder(product, booking)` 所需的 booking 入参。
3
+ *
4
+ * 协议严格对齐 `pisell_os/src/modules/Order/TEMP_ORDER_FIELDS_SUMMARY.md` 的 Bookings 章节:
5
+ * - 顶层只允许出现:schedule_event_id / appointment_status / start_date / start_time / end_date /
6
+ * end_time / select_date / duration / sub_type / like_status / number / resources / relation_forms /
7
+ * holder / metadata / is_all / schedule_id / relation_id / form_id / relation_type / product_uid
8
+ * - bookings[] 不允许出现 `_extend`
9
+ * - bookings[].metadata 走白名单:unique_identification_number / collect_pax / capacity / holder_id / resource_select_type
10
+ * - bookings[].resources[] 只接受协议白名单:form_id / relation_type / relation_id / capacity / like_status / metadata / children
11
+ *
12
+ * `product_uid` / `metadata.unique_identification_number` 不在这里生成:
13
+ * OS `addProductToOrder` 内的 `createLinkedProductAndBooking` 会在最终一步统一改写,
14
+ * 保证商品行 uid 与 booking root 唯一值始终对齐。
15
+ *
16
+ * 复杂 multi-day 展开(createBookingItemsByGroup / concatBookings)首版**不支持**,
17
+ * 由 UI 在 `cart.confirmDetail` 之外通过辅助 API 处理。
18
+ */
19
+ export interface CacheItemToBookingInputOptions {
20
+ /** booking config,用于推导 metadata.resource_select_type(默认从 cacheItem.\_data.resources[0].select_type.type 推断)。 */
21
+ bookingConfig?: any;
22
+ }
23
+ export interface BookingInput {
24
+ schedule_event_id?: number | string;
25
+ start_date?: string;
26
+ start_time?: string;
27
+ end_date?: string;
28
+ end_time?: string;
29
+ select_date?: string;
30
+ duration?: number;
31
+ sub_type?: 'days' | 'minutes' | string;
32
+ is_all?: 0 | 1;
33
+ number?: number;
34
+ holder?: any;
35
+ like_status?: string;
36
+ relation_forms?: any[];
37
+ resources?: BookingResourceInput[];
38
+ metadata?: BookingMetadataInput;
39
+ schedule_id?: number | string;
40
+ relation_id?: number | string;
41
+ form_id?: number | string;
42
+ relation_type?: string;
43
+ }
44
+ export interface BookingResourceInput {
45
+ form_id?: number | string;
46
+ relation_type?: string;
47
+ relation_id?: number | string;
48
+ capacity?: number;
49
+ like_status?: string;
50
+ metadata?: Record<string, any>;
51
+ children?: any[];
52
+ }
53
+ /** custom / package 人数维度快照,与 info2 `_extend.capacity` / `metadata.capacity` 对齐。 */
54
+ export interface BookingCapacityMetadataItem {
55
+ id: string | number;
56
+ value: number;
57
+ name?: Record<string, any> | string;
58
+ }
59
+ export interface BookingMetadataInput {
60
+ /** 由 OS createLinkedProductAndBooking 统一改写,这里不生成。 */
61
+ unique_identification_number?: string;
62
+ collect_pax?: number;
63
+ /**
64
+ * 资源容量快照:custom 多维度时为 `{ id, value, name? }[]`;
65
+ * 仅总和场景可为 number(capacity_snapshot 兼容)。
66
+ */
67
+ capacity?: number | BookingCapacityMetadataItem[];
68
+ /** 协议要求始终提交(即使为 null)。 */
69
+ holder_id: any;
70
+ resource_select_type?: 'single' | 'multiple' | string;
71
+ }
72
+ /**
73
+ * 主入口。
74
+ */
75
+ export declare function cacheItemToBookingInput(cacheItem: any, options?: CacheItemToBookingInputOptions): BookingInput;
@@ -0,0 +1,215 @@
1
+ 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; }
2
+ 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; }
3
+ 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; }
4
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
+ 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); }
6
+ 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); }
7
+ import dayjs from 'dayjs';
8
+ import { isMultiDayProduct, isSessionProduct, getDays } from "./serviceTimes";
9
+ import { getSumCapacity } from "./resources";
10
+ import { flexibleObj } from "./flexible";
11
+
12
+ /**
13
+ * 把 info2 `cacheItem` 转换为 OS `addProductToOrder(product, booking)` 所需的 booking 入参。
14
+ *
15
+ * 协议严格对齐 `pisell_os/src/modules/Order/TEMP_ORDER_FIELDS_SUMMARY.md` 的 Bookings 章节:
16
+ * - 顶层只允许出现:schedule_event_id / appointment_status / start_date / start_time / end_date /
17
+ * end_time / select_date / duration / sub_type / like_status / number / resources / relation_forms /
18
+ * holder / metadata / is_all / schedule_id / relation_id / form_id / relation_type / product_uid
19
+ * - bookings[] 不允许出现 `_extend`
20
+ * - bookings[].metadata 走白名单:unique_identification_number / collect_pax / capacity / holder_id / resource_select_type
21
+ * - bookings[].resources[] 只接受协议白名单:form_id / relation_type / relation_id / capacity / like_status / metadata / children
22
+ *
23
+ * `product_uid` / `metadata.unique_identification_number` 不在这里生成:
24
+ * OS `addProductToOrder` 内的 `createLinkedProductAndBooking` 会在最终一步统一改写,
25
+ * 保证商品行 uid 与 booking root 唯一值始终对齐。
26
+ *
27
+ * 复杂 multi-day 展开(createBookingItemsByGroup / concatBookings)首版**不支持**,
28
+ * 由 UI 在 `cart.confirmDetail` 之外通过辅助 API 处理。
29
+ */
30
+
31
+ /** custom / package 人数维度快照,与 info2 `_extend.capacity` / `metadata.capacity` 对齐。 */
32
+
33
+ /** 将 UI `_extend.capacity[]` 规范化为 booking.metadata.capacity。 */
34
+ function normalizeExtendCapacityForMetadata(capacity) {
35
+ if (!Array.isArray(capacity) || capacity.length === 0) return undefined;
36
+ var normalized = capacity.map(function (item) {
37
+ var _item$value;
38
+ if (!item || _typeof(item) !== 'object') return null;
39
+ if (item.id === undefined || item.id === null) return null;
40
+ var row = {
41
+ id: item.id,
42
+ value: Number((_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : 0)
43
+ };
44
+ if (item.name !== undefined) row.name = item.name;
45
+ return row;
46
+ }).filter(function (item) {
47
+ return item != null;
48
+ });
49
+ return normalized.length > 0 ? normalized : undefined;
50
+ }
51
+ function safeFormat(value, fmt) {
52
+ if (value === undefined || value === null) return undefined;
53
+ var d = dayjs(value);
54
+ if (!d.isValid()) return undefined;
55
+ return d.format(fmt);
56
+ }
57
+
58
+ /** booking 协议 start_time / end_time:统一 HH:mm(不带秒)。 */
59
+ function normalizeTimeString(value) {
60
+ if (value === undefined || value === null) return undefined;
61
+ if (typeof value === 'string') {
62
+ var t = value.trim();
63
+ var hhmmFromHhmmss = t.match(/^(\d{1,2}:\d{2}):\d{2}$/);
64
+ if (hhmmFromHhmmss) return hhmmFromHhmmss[1];
65
+ if (/^\d{1,2}:\d{2}$/.test(t)) return t;
66
+ }
67
+ var d = dayjs(value);
68
+ if (d.isValid()) return d.format('HH:mm');
69
+ return undefined;
70
+ }
71
+ function resolveDurationMinutes(value) {
72
+ if (typeof value === 'number' && Number.isFinite(value)) return value;
73
+ if (typeof value !== 'string') return undefined;
74
+ if (flexibleObj.isFlexible(value)) return flexibleObj.getValue(value);
75
+ var n = Number(value);
76
+ return Number.isNaN(n) ? undefined : n;
77
+ }
78
+
79
+ /**
80
+ * cacheItem._extend.resource 形如 `{ [form_id]: [{ relation_id, form_id, like_status, metadata, children }] }`。
81
+ * 这里扁平化为符合协议的 resources[] 数组;id=0 的「无资源」占位行**保留**(与 info2 业务等价;协议 `relation_id=0` 合法)。
82
+ *
83
+ * 顶层 resources[].capacity 与 info2 `checkResourcesFormat` 一致:Σ capacity[].value(不含 quantity)。
84
+ */
85
+ function flattenResources(cacheItem) {
86
+ var _cacheItem$_extend;
87
+ var resourceMap = (cacheItem === null || cacheItem === void 0 || (_cacheItem$_extend = cacheItem._extend) === null || _cacheItem$_extend === void 0 ? void 0 : _cacheItem$_extend.resource) || {};
88
+ var topLevelCapacity = getSumCapacity(cacheItem, false);
89
+ var result = [];
90
+ Object.values(resourceMap).forEach(function (arr) {
91
+ if (!Array.isArray(arr)) return;
92
+ arr.forEach(function (r) {
93
+ var item = {
94
+ form_id: r === null || r === void 0 ? void 0 : r.form_id,
95
+ relation_type: (r === null || r === void 0 ? void 0 : r.relation_type) || 'form',
96
+ relation_id: r === null || r === void 0 ? void 0 : r.relation_id,
97
+ capacity: topLevelCapacity
98
+ };
99
+ item.like_status = (r === null || r === void 0 ? void 0 : r.like_status) || 'common';
100
+ if ((r === null || r === void 0 ? void 0 : r.metadata) !== undefined) {
101
+ // 协议允许 metadata 自由透传;为了与 info2 行为等价,把 form_name / resource_name / combined_resource 一并保留。
102
+ item.metadata = _objectSpread({}, r.metadata);
103
+ }
104
+ if ((r === null || r === void 0 ? void 0 : r.children) !== undefined) item.children = r.children;
105
+ result.push(item);
106
+ });
107
+ });
108
+ return result;
109
+ }
110
+
111
+ /**
112
+ * 从 cacheItem 中派生 metadata.resource_select_type;优先级:
113
+ * 1. cacheItem._data.resources[0].select_type.type
114
+ * 2. cacheItem.product_resource.resources[0].select_type.type
115
+ * 3. 默认 undefined(由 OS / 后端兜底)。
116
+ */
117
+ function deriveResourceSelectType(cacheItem) {
118
+ var _cacheItem$_data, _cacheItem$product_re;
119
+ var localFirst = cacheItem === null || cacheItem === void 0 || (_cacheItem$_data = cacheItem._data) === null || _cacheItem$_data === void 0 || (_cacheItem$_data = _cacheItem$_data.resources) === null || _cacheItem$_data === void 0 || (_cacheItem$_data = _cacheItem$_data[0]) === null || _cacheItem$_data === void 0 || (_cacheItem$_data = _cacheItem$_data.select_type) === null || _cacheItem$_data === void 0 ? void 0 : _cacheItem$_data.type;
120
+ if (localFirst) return localFirst;
121
+ var productFirst = cacheItem === null || cacheItem === void 0 || (_cacheItem$product_re = cacheItem.product_resource) === null || _cacheItem$product_re === void 0 || (_cacheItem$product_re = _cacheItem$product_re.resources) === null || _cacheItem$product_re === void 0 || (_cacheItem$product_re = _cacheItem$product_re[0]) === null || _cacheItem$product_re === void 0 || (_cacheItem$product_re = _cacheItem$product_re.select_type) === null || _cacheItem$product_re === void 0 ? void 0 : _cacheItem$product_re.type;
122
+ if (productFirst) return productFirst;
123
+ return undefined;
124
+ }
125
+
126
+ /**
127
+ * 主入口。
128
+ */
129
+ export function cacheItemToBookingInput(cacheItem, options) {
130
+ var _ext$other, _options$bookingConfi;
131
+ if (!cacheItem) return {
132
+ metadata: {
133
+ holder_id: null
134
+ }
135
+ };
136
+ var ext = cacheItem._extend || {};
137
+ var isMultiDay = isMultiDayProduct(cacheItem) || ext.is_all === 1 || ext.sub_type === 'days';
138
+ var isSession = isSessionProduct(cacheItem);
139
+ var result = {};
140
+
141
+ // ──── 日期 / 时间 ───────────────────────────────────────────────
142
+ if (isSession && ext !== null && ext !== void 0 && (_ext$other = ext.other) !== null && _ext$other !== void 0 && _ext$other.session) {
143
+ var session = ext.other.session;
144
+ // 优先 _extend 上已按顶部 date 对齐过的起止(catalog cartDetailValue.session → applySessionTimesToExtend)
145
+ result.start_date = safeFormat(ext.start_date || ext.startDate || session.start_at, 'YYYY-MM-DD');
146
+ result.start_time = normalizeTimeString(ext.start_time) || normalizeTimeString(session.start_time) || safeFormat(session.start_at, 'HH:mm');
147
+ result.end_date = safeFormat(ext.end_date || ext.endDate || session.end_at, 'YYYY-MM-DD');
148
+ result.end_time = normalizeTimeString(ext.end_time) || normalizeTimeString(session.end_time) || safeFormat(session.end_at, 'HH:mm');
149
+ } else {
150
+ result.start_date = safeFormat(ext.start_date || ext.startDate, 'YYYY-MM-DD');
151
+ result.start_time = normalizeTimeString(ext.start_time) || safeFormat(ext.startDate, 'HH:mm');
152
+ result.end_date = safeFormat(ext.end_date || ext.endDate, 'YYYY-MM-DD');
153
+ result.end_time = normalizeTimeString(ext.end_time) || safeFormat(ext.endDate, 'HH:mm');
154
+ }
155
+
156
+ // ──── duration / sub_type / is_all ──────────────────────────────
157
+ if (isMultiDay) {
158
+ result.is_all = 1;
159
+ result.sub_type = 'days';
160
+ result.duration = Number(ext.duration) || getDays(cacheItem, 'days');
161
+ // 全天选择日期 = 起始日
162
+ if (result.start_date) result.select_date = result.start_date;
163
+ // 跨日结束时刻与开始一致(如 11:24),避免 endDate 仅日期落为 00:00
164
+ if (result.start_time && (!result.end_time || result.end_time === '00:00')) {
165
+ result.end_time = result.start_time;
166
+ }
167
+ } else {
168
+ result.is_all = 0;
169
+ result.sub_type = ext.sub_type || 'minutes';
170
+ var duration = resolveDurationMinutes(ext.duration);
171
+ if (duration !== undefined) result.duration = duration;
172
+ }
173
+
174
+ // ──── number(人数/容量占用) ───────────────────────────────────
175
+ result.number = getSumCapacity(cacheItem, true);
176
+
177
+ // ──── resources ─────────────────────────────────────────────────
178
+ result.resources = flattenResources(cacheItem);
179
+
180
+ // ──── holder / relation_forms / like_status / schedule_event_id ──
181
+ if (ext.holder !== undefined) result.holder = ext.holder;
182
+ if (Array.isArray(ext.relation_forms)) result.relation_forms = ext.relation_forms;
183
+ // 与 info2 booking/components/footer/utils formatBooking 一致:默认 common
184
+ result.like_status = ext.like_status || 'common';
185
+ if (cacheItem.schedule_event_id !== undefined) {
186
+ result.schedule_event_id = cacheItem.schedule_event_id;
187
+ }
188
+
189
+ // ──── metadata(严格白名单) ────────────────────────────────────
190
+ var metadata = {
191
+ holder_id: null
192
+ };
193
+ if (ext.holder_id !== undefined && ext.holder_id !== null) {
194
+ metadata.holder_id = ext.holder_id;
195
+ }
196
+ if (ext.collect_pax !== undefined) metadata.collect_pax = ext.collect_pax;
197
+ // 与 info2 formatMetaData 一致:优先写入完整人数维度数组,供编辑回显 / 详情回灌。
198
+ var extendCapacity = normalizeExtendCapacityForMetadata(ext.capacity);
199
+ if (extendCapacity) {
200
+ metadata.capacity = extendCapacity;
201
+ } else if (ext.capacity_snapshot !== undefined) {
202
+ metadata.capacity = ext.capacity_snapshot;
203
+ }
204
+ var selectType = deriveResourceSelectType(cacheItem) || (options === null || options === void 0 || (_options$bookingConfi = options.bookingConfig) === null || _options$bookingConfi === void 0 ? void 0 : _options$bookingConfi.resource_select_type);
205
+ if (selectType) metadata.resource_select_type = selectType;
206
+ // unique_identification_number 不在这里生成(由 OS createLinkedProductAndBooking 统一写)。
207
+ result.metadata = metadata;
208
+
209
+ // ──── booking root 占位字段(与 TEMP_ORDER_FIELDS_SUMMARY 一致) ──
210
+ result.schedule_id = 0;
211
+ result.relation_id = 0;
212
+ result.form_id = 0;
213
+ result.relation_type = '';
214
+ return result;
215
+ }