@pisell/pisellos 2.2.181 → 2.2.183

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 (173) 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 +276 -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.js +4 -3
  35. package/dist/modules/Discount/types.d.ts +1 -0
  36. package/dist/modules/Order/index.d.ts +100 -9
  37. package/dist/modules/Order/index.js +1447 -499
  38. package/dist/modules/Order/types.d.ts +201 -18
  39. package/dist/modules/Order/types.js +31 -0
  40. package/dist/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  41. package/dist/modules/Order/utils/manualProductDiscount.js +210 -0
  42. package/dist/modules/Order/utils.d.ts +83 -1
  43. package/dist/modules/Order/utils.js +405 -61
  44. package/dist/modules/Product/index.d.ts +1 -1
  45. package/dist/modules/Quotation/index.d.ts +0 -1
  46. package/dist/modules/Quotation/index.js +23 -21
  47. package/dist/modules/Rules/index.d.ts +4 -0
  48. package/dist/modules/Rules/index.js +43 -39
  49. package/dist/modules/Rules/types.d.ts +1 -0
  50. package/dist/modules/SalesSummary/index.js +4 -2
  51. package/dist/modules/SalesSummary/utils.js +21 -7
  52. package/dist/modules/Schedule/index.js +6 -2
  53. package/dist/modules/index.d.ts +1 -0
  54. package/dist/modules/index.js +2 -1
  55. package/dist/server/index.js +87 -29
  56. package/dist/server/modules/order/index.d.ts +23 -0
  57. package/dist/server/modules/order/index.js +123 -46
  58. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  59. package/dist/server/modules/products/index.d.ts +1 -1
  60. package/dist/server/modules/products/index.js +130 -113
  61. package/dist/server/modules/schedule/index.js +13 -6
  62. package/dist/solution/BaseSales/index.d.ts +89 -7
  63. package/dist/solution/BaseSales/index.js +1504 -380
  64. package/dist/solution/BaseSales/types.d.ts +67 -1
  65. package/dist/solution/BaseSales/types.js +3 -1
  66. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  67. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  68. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  69. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  70. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  71. package/dist/solution/BaseSales/utils.js +46 -8
  72. package/dist/solution/BookingByStep/index.d.ts +1 -1
  73. package/dist/solution/BookingTicket/index.d.ts +151 -1
  74. package/dist/solution/BookingTicket/index.js +848 -184
  75. package/dist/solution/BookingTicket/types.d.ts +2 -0
  76. package/dist/solution/BookingTicket/types.js +3 -0
  77. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  78. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  79. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  80. package/dist/solution/ScanOrder/index.d.ts +9 -3
  81. package/dist/solution/ScanOrder/index.js +231 -128
  82. package/dist/solution/ScanOrder/utils.js +46 -8
  83. package/dist/solution/VenueBooking/index.d.ts +5 -2
  84. package/dist/solution/VenueBooking/index.js +103 -55
  85. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  86. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  87. package/lib/modules/BookingContext/index.d.ts +37 -0
  88. package/lib/modules/BookingContext/index.js +297 -0
  89. package/lib/modules/BookingContext/types.d.ts +102 -0
  90. package/lib/modules/BookingContext/types.js +34 -0
  91. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  92. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +271 -0
  93. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  94. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +141 -0
  95. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +75 -0
  96. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +198 -0
  97. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  98. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  99. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  100. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  101. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  102. package/lib/modules/BookingContext/utils/index.js +43 -0
  103. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  104. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  105. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  106. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  107. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  108. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  109. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  110. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  111. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  112. package/lib/modules/BookingContext/utils/resources.js +377 -0
  113. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  114. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  115. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  116. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  117. package/lib/modules/Customer/index.d.ts +6 -0
  118. package/lib/modules/Customer/index.js +26 -11
  119. package/lib/modules/Customer/types.d.ts +2 -0
  120. package/lib/modules/Discount/index.js +5 -1
  121. package/lib/modules/Discount/types.d.ts +1 -0
  122. package/lib/modules/Order/index.d.ts +100 -9
  123. package/lib/modules/Order/index.js +751 -160
  124. package/lib/modules/Order/types.d.ts +201 -18
  125. package/lib/modules/Order/types.js +1 -0
  126. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  127. package/lib/modules/Order/utils/manualProductDiscount.js +206 -0
  128. package/lib/modules/Order/utils.d.ts +83 -1
  129. package/lib/modules/Order/utils.js +340 -22
  130. package/lib/modules/Product/index.d.ts +1 -1
  131. package/lib/modules/Quotation/index.d.ts +0 -1
  132. package/lib/modules/Quotation/index.js +18 -15
  133. package/lib/modules/Rules/index.d.ts +4 -0
  134. package/lib/modules/Rules/index.js +26 -27
  135. package/lib/modules/Rules/types.d.ts +1 -0
  136. package/lib/modules/SalesSummary/index.js +4 -2
  137. package/lib/modules/SalesSummary/utils.js +21 -7
  138. package/lib/modules/Schedule/index.js +3 -1
  139. package/lib/modules/index.d.ts +1 -0
  140. package/lib/modules/index.js +3 -1
  141. package/lib/server/index.js +41 -4
  142. package/lib/server/modules/order/index.d.ts +23 -0
  143. package/lib/server/modules/order/index.js +46 -14
  144. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  145. package/lib/server/modules/products/index.d.ts +1 -1
  146. package/lib/server/modules/products/index.js +30 -20
  147. package/lib/server/modules/schedule/index.js +2 -1
  148. package/lib/solution/BaseSales/index.d.ts +89 -7
  149. package/lib/solution/BaseSales/index.js +743 -23
  150. package/lib/solution/BaseSales/types.d.ts +67 -1
  151. package/lib/solution/BaseSales/types.js +3 -1
  152. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  153. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  154. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  155. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  156. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  157. package/lib/solution/BaseSales/utils.js +46 -6
  158. package/lib/solution/BookingByStep/index.d.ts +1 -1
  159. package/lib/solution/BookingTicket/index.d.ts +151 -1
  160. package/lib/solution/BookingTicket/index.js +389 -9
  161. package/lib/solution/BookingTicket/types.d.ts +2 -0
  162. package/lib/solution/BookingTicket/types.js +6 -0
  163. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  164. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  165. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  166. package/lib/solution/ScanOrder/index.d.ts +9 -3
  167. package/lib/solution/ScanOrder/index.js +147 -66
  168. package/lib/solution/ScanOrder/utils.js +46 -6
  169. package/lib/solution/VenueBooking/index.d.ts +5 -2
  170. package/lib/solution/VenueBooking/index.js +50 -14
  171. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  172. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  173. package/package.json +1 -1
@@ -0,0 +1,271 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/modules/BookingContext/utils/buildCacheItemFromOrderLine.ts
30
+ var buildCacheItemFromOrderLine_exports = {};
31
+ __export(buildCacheItemFromOrderLine_exports, {
32
+ buildCacheItemFromOrderLine: () => buildCacheItemFromOrderLine
33
+ });
34
+ module.exports = __toCommonJS(buildCacheItemFromOrderLine_exports);
35
+ var import_dayjs = __toESM(require("dayjs"));
36
+ var import_manualProductDiscount = require("../../Order/utils/manualProductDiscount");
37
+ function safeFormat(value, fmt) {
38
+ if (value === void 0 || value === null)
39
+ return void 0;
40
+ const d = (0, import_dayjs.default)(value);
41
+ if (!d.isValid())
42
+ return void 0;
43
+ return d.format(fmt);
44
+ }
45
+ function normalizeTimeString(value) {
46
+ if (value === void 0 || value === null)
47
+ return void 0;
48
+ if (typeof value === "string") {
49
+ const t = value.trim();
50
+ const hhmmFromHhmmss = t.match(/^(\d{1,2}:\d{2}):\d{2}$/);
51
+ if (hhmmFromHhmmss)
52
+ return hhmmFromHhmmss[1];
53
+ if (/^\d{1,2}:\d{2}$/.test(t))
54
+ return t;
55
+ }
56
+ const d = (0, import_dayjs.default)(value);
57
+ if (d.isValid())
58
+ return d.format("HH:mm");
59
+ return void 0;
60
+ }
61
+ function unflattenResourceMap(resources) {
62
+ const map = {};
63
+ if (!Array.isArray(resources))
64
+ return map;
65
+ resources.forEach((r) => {
66
+ const formId = r == null ? void 0 : r.form_id;
67
+ if (formId === void 0 || formId === null)
68
+ return;
69
+ const key = String(formId);
70
+ if (!map[key])
71
+ map[key] = [];
72
+ map[key].push({
73
+ form_id: formId,
74
+ relation_id: r.relation_id,
75
+ relation_type: r.relation_type || "form",
76
+ like_status: r.like_status || "common",
77
+ metadata: r.metadata ? { ...r.metadata } : void 0,
78
+ children: r.children
79
+ });
80
+ });
81
+ return map;
82
+ }
83
+ function resolveCapacityFromBooking(booking) {
84
+ var _a;
85
+ const metaCap = (_a = booking.metadata) == null ? void 0 : _a.capacity;
86
+ if (Array.isArray(metaCap) && metaCap.length > 0) {
87
+ return metaCap.map((item) => {
88
+ if (!item || typeof item !== "object")
89
+ return null;
90
+ if (item.id === void 0 || item.id === null)
91
+ return null;
92
+ const row = {
93
+ id: item.id,
94
+ value: Number(item.value ?? 0)
95
+ };
96
+ if (item.name !== void 0)
97
+ row.name = item.name;
98
+ return row;
99
+ }).filter((item) => item != null);
100
+ }
101
+ if (typeof metaCap === "number" && Number.isFinite(metaCap)) {
102
+ return [{ id: 0, value: metaCap, name: "" }];
103
+ }
104
+ return [];
105
+ }
106
+ function resolveDurationForExtend(booking) {
107
+ const duration = booking.duration;
108
+ if (booking.sub_type === "days" || booking.is_all === 1) {
109
+ return duration;
110
+ }
111
+ if (typeof duration === "number" && Number.isFinite(duration)) {
112
+ return duration;
113
+ }
114
+ return duration;
115
+ }
116
+ function resolveTopLevelDuration(booking, sourceProduct) {
117
+ if ((sourceProduct == null ? void 0 : sourceProduct.duration) !== void 0) {
118
+ return sourceProduct.duration;
119
+ }
120
+ const raw = booking.duration;
121
+ if (raw == null || raw === "")
122
+ return void 0;
123
+ if (typeof raw === "object" && raw.type) {
124
+ return raw;
125
+ }
126
+ const subType = booking.sub_type === "days" ? "days" : "minutes";
127
+ const value = Number(raw);
128
+ if (!Number.isFinite(value) || value <= 0)
129
+ return void 0;
130
+ return { type: subType, value };
131
+ }
132
+ function resolveProductTitle(product, booking, sourceProduct) {
133
+ var _a, _b;
134
+ const metadata = product.metadata || {};
135
+ return (sourceProduct == null ? void 0 : sourceProduct.title) ?? (sourceProduct == null ? void 0 : sourceProduct.name) ?? metadata.product_title ?? metadata.product_name ?? ((_a = booking == null ? void 0 : booking.product) == null ? void 0 : _a.title) ?? ((_b = booking == null ? void 0 : booking.detail) == null ? void 0 : _b.product_title) ?? "";
136
+ }
137
+ function synthesizeProductResourceFromBooking(booking) {
138
+ const rows = booking == null ? void 0 : booking.resources;
139
+ if (!Array.isArray(rows) || rows.length === 0)
140
+ return void 0;
141
+ const relationIdsByForm = /* @__PURE__ */ new Map();
142
+ rows.forEach((row) => {
143
+ const formId = row == null ? void 0 : row.form_id;
144
+ const relationId = Number(row == null ? void 0 : row.relation_id);
145
+ if (formId == null || formId === "" || !Number.isFinite(relationId) || relationId <= 0) {
146
+ return;
147
+ }
148
+ const list = relationIdsByForm.get(formId) ?? [];
149
+ if (!list.includes(relationId)) {
150
+ list.push(relationId);
151
+ }
152
+ relationIdsByForm.set(formId, list);
153
+ });
154
+ if (relationIdsByForm.size === 0)
155
+ return void 0;
156
+ return {
157
+ resources: Array.from(relationIdsByForm.entries()).map(([formId, relationIds]) => ({
158
+ id: formId,
159
+ status: 1,
160
+ type: "form",
161
+ code: "",
162
+ optional_resource: relationIds,
163
+ default_resource: []
164
+ }))
165
+ };
166
+ }
167
+ function buildCacheItemFromOrderLine(input) {
168
+ var _a, _b, _c, _d, _e, _f;
169
+ const { product, booking, sourceProduct } = input;
170
+ const resolvedId = product.product_id ?? (sourceProduct == null ? void 0 : sourceProduct.id);
171
+ const selling = Number(product.selling_price ?? 0);
172
+ const original = Number(product.original_price ?? selling);
173
+ const startDate = safeFormat(booking.start_date, "YYYY-MM-DD");
174
+ const endDate = safeFormat(booking.end_date, "YYYY-MM-DD");
175
+ const startTime = normalizeTimeString(booking.start_time);
176
+ const endTime = normalizeTimeString(booking.end_time);
177
+ const resource = unflattenResourceMap(booking.resources);
178
+ const capacity = resolveCapacityFromBooking(booking);
179
+ const holderId = ((_a = booking.metadata) == null ? void 0 : _a.holder_id) ?? booking.holder_id;
180
+ const productTitle = resolveProductTitle(product, booking, sourceProduct);
181
+ const other = {
182
+ product_variant_id: product.product_variant_id ?? 0,
183
+ option: Array.isArray(product.product_option_item) ? [...product.product_option_item] : [],
184
+ bundle: Array.isArray(product.product_bundle) ? [...product.product_bundle] : []
185
+ };
186
+ const extend = {
187
+ start_date: startDate ? (0, import_dayjs.default)(startDate) : void 0,
188
+ end_date: endDate ? (0, import_dayjs.default)(endDate) : void 0,
189
+ startDate: startDate ? (0, import_dayjs.default)(startDate) : void 0,
190
+ endDate: endDate ? (0, import_dayjs.default)(endDate) : void 0,
191
+ start_time: startTime,
192
+ end_time: endTime,
193
+ duration: resolveDurationForExtend(booking),
194
+ sub_type: booking.sub_type,
195
+ quantity: product.num ?? 1,
196
+ product_name: productTitle,
197
+ note: product.note ?? ((_b = booking == null ? void 0 : booking.detail) == null ? void 0 : _b.note) ?? "",
198
+ price: selling,
199
+ total: selling,
200
+ origin_total: original,
201
+ resource,
202
+ capacity,
203
+ holder_id: holderId,
204
+ other,
205
+ like_status: booking.like_status || "common",
206
+ discount_reason: (0, import_manualProductDiscount.resolveManualDiscountMessage)(
207
+ product.discount_list,
208
+ (_c = product.metadata) == null ? void 0 : _c.product_discount_reason
209
+ ) || void 0
210
+ };
211
+ const manualDiscount = (product.discount_list || []).find((d) => (d == null ? void 0 : d.type) === "product");
212
+ if (manualDiscount && extend.origin_total === selling) {
213
+ const manualAmount = Number(manualDiscount.amount ?? 0);
214
+ if (Number.isFinite(manualAmount) && manualAmount > 0) {
215
+ extend.origin_total = selling + manualAmount;
216
+ }
217
+ }
218
+ if (((_d = product.metadata) == null ? void 0 : _d.price_override) != null || manualDiscount) {
219
+ extend.priceOverride = selling;
220
+ }
221
+ if (booking.holder !== void 0) {
222
+ extend.holder = booking.holder;
223
+ }
224
+ if (Array.isArray(booking.relation_forms)) {
225
+ extend.relation_forms = booking.relation_forms;
226
+ }
227
+ const base = {
228
+ ...sourceProduct || {},
229
+ id: resolvedId,
230
+ product_id: resolvedId,
231
+ extension_type: (sourceProduct == null ? void 0 : sourceProduct.extension_type) ?? ((_e = booking == null ? void 0 : booking.product) == null ? void 0 : _e.extension_type) ?? (sourceProduct == null ? void 0 : sourceProduct.extension_type),
232
+ title: productTitle || (sourceProduct == null ? void 0 : sourceProduct.title) || ((_f = booking == null ? void 0 : booking.product) == null ? void 0 : _f.title),
233
+ price: (sourceProduct == null ? void 0 : sourceProduct.price) ?? selling,
234
+ selling_price: product.selling_price,
235
+ original_price: product.original_price,
236
+ _extend: extend,
237
+ new: 0,
238
+ autoClose: false,
239
+ order_detail_id: product.order_detail_id ?? null,
240
+ booking_id: booking.id ?? booking.booking_id ?? 0
241
+ };
242
+ if ((sourceProduct == null ? void 0 : sourceProduct.capacity) !== void 0) {
243
+ base.capacity = sourceProduct.capacity;
244
+ }
245
+ const topLevelDuration = resolveTopLevelDuration(booking, sourceProduct);
246
+ if (topLevelDuration !== void 0) {
247
+ base.duration = topLevelDuration;
248
+ }
249
+ if ((sourceProduct == null ? void 0 : sourceProduct.product_resource) !== void 0) {
250
+ base.product_resource = sourceProduct.product_resource;
251
+ } else {
252
+ const synthesized = synthesizeProductResourceFromBooking(booking);
253
+ if (synthesized) {
254
+ base.product_resource = synthesized;
255
+ }
256
+ }
257
+ if (Array.isArray(sourceProduct == null ? void 0 : sourceProduct.schedules) && sourceProduct.schedules.length) {
258
+ base.schedules = sourceProduct.schedules;
259
+ }
260
+ if (Array.isArray(sourceProduct == null ? void 0 : sourceProduct["schedule.ids"]) && sourceProduct["schedule.ids"].length) {
261
+ base["schedule.ids"] = sourceProduct["schedule.ids"];
262
+ }
263
+ if (booking.schedule_event_id !== void 0) {
264
+ base.schedule_event_id = booking.schedule_event_id;
265
+ }
266
+ return base;
267
+ }
268
+ // Annotate the CommonJS export names for ESM import in node:
269
+ 0 && (module.exports = {
270
+ buildCacheItemFromOrderLine
271
+ });
@@ -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,141 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.ts
20
+ var buildNormalProductCacheItemFromOrderLine_exports = {};
21
+ __export(buildNormalProductCacheItemFromOrderLine_exports, {
22
+ buildNormalProductCacheItemFromOrderLine: () => buildNormalProductCacheItemFromOrderLine
23
+ });
24
+ module.exports = __toCommonJS(buildNormalProductCacheItemFromOrderLine_exports);
25
+ function resolveSourceProductPrice(product, sourceProduct) {
26
+ var _a, _b, _c;
27
+ const metadata = product.metadata || {};
28
+ if (metadata.source_product_price !== void 0 && metadata.source_product_price !== null) {
29
+ const parsed = Number(metadata.source_product_price);
30
+ if (Number.isFinite(parsed))
31
+ return parsed;
32
+ }
33
+ const variantId = Number(product.product_variant_id || 0);
34
+ if (variantId > 0) {
35
+ const variantList = ((_a = metadata.origin) == null ? void 0 : _a.variant) ?? (sourceProduct == null ? void 0 : sourceProduct.variant);
36
+ if (Array.isArray(variantList)) {
37
+ const matched = variantList.find((v) => Number(v == null ? void 0 : v.id) === variantId);
38
+ const variantPrice = (matched == null ? void 0 : matched.price) ?? (matched == null ? void 0 : matched.base_price);
39
+ if (variantPrice !== void 0 && variantPrice !== null) {
40
+ const parsed = Number(variantPrice);
41
+ if (Number.isFinite(parsed))
42
+ return parsed;
43
+ }
44
+ }
45
+ }
46
+ const catalogPrice = (sourceProduct == null ? void 0 : sourceProduct.price) ?? (sourceProduct == null ? void 0 : sourceProduct.base_price);
47
+ if (catalogPrice !== void 0 && catalogPrice !== null) {
48
+ const parsed = Number(catalogPrice);
49
+ if (Number.isFinite(parsed))
50
+ return parsed;
51
+ }
52
+ const originPrice = ((_b = metadata.origin) == null ? void 0 : _b.price) ?? ((_c = metadata.origin) == null ? void 0 : _c.base_price);
53
+ if (originPrice !== void 0 && originPrice !== null) {
54
+ const parsed = Number(originPrice);
55
+ if (Number.isFinite(parsed))
56
+ return parsed;
57
+ }
58
+ return Number(product.selling_price ?? 0);
59
+ }
60
+ function mapOrderBundleToOtherBundle(bundle) {
61
+ return bundle.map((item) => {
62
+ const catalogOriginal = item.original_price ?? item.product_price ?? item.price ?? item.bundle_selling_price;
63
+ const selling = item.bundle_selling_price ?? item.price ?? catalogOriginal;
64
+ const { bundle_selling_price: _omitBundleSelling, ...rest } = item;
65
+ return {
66
+ ...rest,
67
+ price: selling,
68
+ original_price: catalogOriginal,
69
+ original_total: item.original_total ?? catalogOriginal,
70
+ num: item.num ?? item.quantity ?? 1,
71
+ quantity: item.quantity ?? item.num ?? 1
72
+ };
73
+ });
74
+ }
75
+ function buildNormalProductCacheItemFromOrderLine(input) {
76
+ var _a, _b, _c, _d;
77
+ const { product, sourceProduct } = input;
78
+ const resolvedId = product.product_id ?? (sourceProduct == null ? void 0 : sourceProduct.id);
79
+ const sourcePrice = resolveSourceProductPrice(product, sourceProduct);
80
+ const selling = Number(product.selling_price ?? 0);
81
+ const original = Number(product.original_price ?? selling);
82
+ const uid = (_a = product.metadata) == null ? void 0 : _a.unique_identification_number;
83
+ const option = Array.isArray(product.product_option_item) ? [...product.product_option_item] : [];
84
+ const bundle = mapOrderBundleToOtherBundle(
85
+ Array.isArray(product.product_bundle) ? product.product_bundle : []
86
+ );
87
+ const originExtend = (_c = (_b = product.metadata) == null ? void 0 : _b.origin) == null ? void 0 : _c._extend;
88
+ const other = {
89
+ product_id: resolvedId,
90
+ product_variant_id: product.product_variant_id ?? 0,
91
+ option,
92
+ bundle: ((_d = originExtend == null ? void 0 : originExtend.other) == null ? void 0 : _d.bundle) ? JSON.parse(JSON.stringify(originExtend.other.bundle)) : bundle,
93
+ quantity: product.num ?? 1
94
+ };
95
+ const skuValue = {
96
+ product_id: resolvedId,
97
+ product_variant_id: product.product_variant_id ?? 0,
98
+ option: other.option,
99
+ bundle: other.bundle
100
+ };
101
+ const extend = {
102
+ quantity: product.num ?? 1,
103
+ product_name: (sourceProduct == null ? void 0 : sourceProduct.title) ?? "",
104
+ note: product.note ?? "",
105
+ // v2:_extend.price 为主商品 source 价;行 composite 用 total / origin_total 展示
106
+ price: (originExtend == null ? void 0 : originExtend.price) ?? sourcePrice,
107
+ total: (originExtend == null ? void 0 : originExtend.total) ?? selling,
108
+ origin_total: (originExtend == null ? void 0 : originExtend.origin_total) ?? original,
109
+ other,
110
+ skuValue: JSON.parse(JSON.stringify(skuValue)),
111
+ _skuValue: JSON.parse(JSON.stringify(skuValue)),
112
+ isNormalProduct: true,
113
+ ...(originExtend == null ? void 0 : originExtend.priceOverride) !== void 0 ? { priceOverride: originExtend.priceOverride } : {},
114
+ ...(originExtend == null ? void 0 : originExtend.bundle_edit) !== void 0 ? { bundle_edit: originExtend.bundle_edit } : {}
115
+ };
116
+ if ((originExtend == null ? void 0 : originExtend.skuValue) || (originExtend == null ? void 0 : originExtend._skuValue)) {
117
+ extend.skuValue = JSON.parse(
118
+ JSON.stringify(originExtend.skuValue || originExtend._skuValue)
119
+ );
120
+ extend._skuValue = JSON.parse(JSON.stringify(extend.skuValue));
121
+ }
122
+ return {
123
+ ...sourceProduct || {},
124
+ id: resolvedId,
125
+ product_id: resolvedId,
126
+ _id: uid,
127
+ title: sourceProduct == null ? void 0 : sourceProduct.title,
128
+ price: (sourceProduct == null ? void 0 : sourceProduct.price) ?? sourcePrice,
129
+ selling_price: product.selling_price,
130
+ original_price: product.original_price,
131
+ note: product.note,
132
+ order_detail_id: product.order_detail_id ?? null,
133
+ new: 0,
134
+ autoClose: true,
135
+ _extend: extend
136
+ };
137
+ }
138
+ // Annotate the CommonJS export names for ESM import in node:
139
+ 0 && (module.exports = {
140
+ buildNormalProductCacheItemFromOrderLine
141
+ });
@@ -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;