@pisell/pisellos 2.2.175 → 2.2.176

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 (172) 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 +84 -17
  38. package/dist/modules/Order/index.js +1239 -495
  39. package/dist/modules/Order/types.d.ts +198 -18
  40. package/dist/modules/Order/types.js +31 -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 +50 -1
  44. package/dist/modules/Order/utils.js +261 -31
  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 +26 -10
  49. package/dist/modules/SalesSummary/index.js +4 -2
  50. package/dist/modules/SalesSummary/utils.js +3 -3
  51. package/dist/modules/Schedule/index.js +6 -2
  52. package/dist/modules/index.d.ts +1 -0
  53. package/dist/modules/index.js +2 -1
  54. package/dist/server/index.js +87 -29
  55. package/dist/server/modules/order/utils/filterOrders.js +20 -6
  56. package/dist/server/modules/products/index.d.ts +1 -1
  57. package/dist/server/modules/products/index.js +130 -113
  58. package/dist/server/modules/schedule/index.js +13 -6
  59. package/dist/solution/BaseSales/index.d.ts +89 -7
  60. package/dist/solution/BaseSales/index.js +1484 -365
  61. package/dist/solution/BaseSales/types.d.ts +67 -1
  62. package/dist/solution/BaseSales/types.js +3 -1
  63. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  64. package/dist/solution/BaseSales/utils/cartPromotion.js +1258 -0
  65. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  66. package/dist/solution/BaseSales/utils/quotationPrice.js +237 -0
  67. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +68 -16
  68. package/dist/solution/BaseSales/utils.js +46 -8
  69. package/dist/solution/BookingByStep/index.d.ts +1 -1
  70. package/dist/solution/BookingTicket/index.d.ts +133 -1
  71. package/dist/solution/BookingTicket/index.js +780 -175
  72. package/dist/solution/BookingTicket/types.d.ts +2 -0
  73. package/dist/solution/BookingTicket/types.js +3 -0
  74. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  75. package/dist/solution/BookingTicket/utils/addProductDecision.js +346 -0
  76. package/dist/solution/BookingTicket/utils/cartView.js +4 -2
  77. package/dist/solution/ScanOrder/index.d.ts +9 -3
  78. package/dist/solution/ScanOrder/index.js +231 -128
  79. package/dist/solution/ScanOrder/utils.js +46 -8
  80. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  81. package/dist/solution/ShopDiscount/index.js +18 -23
  82. package/dist/solution/VenueBooking/index.d.ts +5 -9
  83. package/dist/solution/VenueBooking/index.js +103 -55
  84. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  85. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  86. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  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 +207 -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.d.ts +2 -4
  121. package/lib/modules/Discount/index.js +8 -63
  122. package/lib/modules/Discount/types.d.ts +1 -7
  123. package/lib/modules/Order/index.d.ts +84 -17
  124. package/lib/modules/Order/index.js +588 -145
  125. package/lib/modules/Order/types.d.ts +198 -18
  126. package/lib/modules/Order/types.js +1 -0
  127. package/lib/modules/Order/utils/manualProductDiscount.d.ts +106 -0
  128. package/lib/modules/Order/utils/manualProductDiscount.js +207 -0
  129. package/lib/modules/Order/utils.d.ts +50 -1
  130. package/lib/modules/Order/utils.js +229 -21
  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 +22 -14
  135. package/lib/modules/SalesSummary/index.js +4 -2
  136. package/lib/modules/SalesSummary/utils.js +3 -3
  137. package/lib/modules/Schedule/index.js +3 -1
  138. package/lib/modules/index.d.ts +1 -0
  139. package/lib/modules/index.js +3 -1
  140. package/lib/server/index.js +41 -4
  141. package/lib/server/modules/order/utils/filterOrders.js +12 -4
  142. package/lib/server/modules/products/index.d.ts +1 -1
  143. package/lib/server/modules/products/index.js +30 -20
  144. package/lib/server/modules/schedule/index.js +2 -1
  145. package/lib/solution/BaseSales/index.d.ts +89 -7
  146. package/lib/solution/BaseSales/index.js +736 -22
  147. package/lib/solution/BaseSales/types.d.ts +67 -1
  148. package/lib/solution/BaseSales/types.js +3 -1
  149. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +275 -0
  150. package/lib/solution/BaseSales/utils/cartPromotion.js +836 -0
  151. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  152. package/lib/solution/BaseSales/utils/quotationPrice.js +277 -0
  153. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +71 -12
  154. package/lib/solution/BaseSales/utils.js +46 -6
  155. package/lib/solution/BookingByStep/index.d.ts +1 -1
  156. package/lib/solution/BookingTicket/index.d.ts +133 -1
  157. package/lib/solution/BookingTicket/index.js +352 -8
  158. package/lib/solution/BookingTicket/types.d.ts +2 -0
  159. package/lib/solution/BookingTicket/types.js +6 -0
  160. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +113 -0
  161. package/lib/solution/BookingTicket/utils/addProductDecision.js +318 -0
  162. package/lib/solution/BookingTicket/utils/cartView.js +4 -2
  163. package/lib/solution/ScanOrder/index.d.ts +9 -3
  164. package/lib/solution/ScanOrder/index.js +147 -66
  165. package/lib/solution/ScanOrder/utils.js +46 -6
  166. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  167. package/lib/solution/ShopDiscount/index.js +2 -4
  168. package/lib/solution/VenueBooking/index.d.ts +5 -9
  169. package/lib/solution/VenueBooking/index.js +50 -14
  170. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  171. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  172. package/package.json +2 -2
@@ -0,0 +1,7 @@
1
+ import type { QuotationModule } from '../../../modules/Quotation';
2
+ import type { BaseSalesCalculateProductBookingPriceParams, BaseSalesProductBookingPriceResult } from '../types';
3
+ interface BuildBaseSalesQuotationPriceParams extends BaseSalesCalculateProductBookingPriceParams {
4
+ quotation?: Pick<QuotationModule, 'getPriceForProduct' | 'getQuotationShelfId'> | null;
5
+ }
6
+ export declare function calculateBaseSalesProductBookingPrice(params: BuildBaseSalesQuotationPriceParams): BaseSalesProductBookingPriceResult;
7
+ export {};
@@ -0,0 +1,237 @@
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
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ import dayjs from 'dayjs';
8
+ import Decimal from 'decimal.js';
9
+ function toFiniteNumber(value) {
10
+ var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
11
+ var parsedValue = Number(value);
12
+ if (!Number.isFinite(parsedValue)) return fallback;
13
+ return parsedValue;
14
+ }
15
+ function toPositiveInt(value) {
16
+ var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
17
+ var parsedValue = Math.floor(Number(value));
18
+ if (!Number.isFinite(parsedValue) || parsedValue < 1) return fallback;
19
+ return parsedValue;
20
+ }
21
+ function toPriceString(value) {
22
+ return new Decimal(Number(value) || 0).toDecimalPlaces(2).toFixed(2);
23
+ }
24
+ function normalizeDateTime(value) {
25
+ if (typeof value !== 'string' || !value.trim()) return null;
26
+ var normalized = value.includes(':') ? value : "".concat(value, " 00:00:00");
27
+ var datetime = dayjs(normalized);
28
+ if (!datetime.isValid()) return null;
29
+ return datetime;
30
+ }
31
+ function buildBookingDateTime(date, time) {
32
+ if (typeof date !== 'string' || !date.trim()) return null;
33
+ var timeText = typeof time === 'string' && time.trim() ? time.trim() : '00:00';
34
+ var datetime = dayjs("".concat(date.trim(), " ").concat(timeText));
35
+ if (!datetime.isValid()) return null;
36
+ return datetime;
37
+ }
38
+ function getDurationUnit(type) {
39
+ var normalizedType = String(type || '').toLowerCase();
40
+ if (normalizedType === 'day' || normalizedType === 'days') return 'day';
41
+ if (normalizedType === 'minute' || normalizedType === 'minutes') return 'minute';
42
+ return null;
43
+ }
44
+ function getProductId(product) {
45
+ var _product$product_id;
46
+ var productId = toFiniteNumber((_product$product_id = product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : product.id, NaN);
47
+ if (!Number.isFinite(productId)) return null;
48
+ return productId;
49
+ }
50
+ function getProductVariantId(product) {
51
+ var _product$product_vari;
52
+ var variantId = toFiniteNumber((_product$product_vari = product.product_variant_id) !== null && _product$product_vari !== void 0 ? _product$product_vari : product.variant_id, 0);
53
+ if (!Number.isFinite(variantId) || variantId <= 0) return undefined;
54
+ return variantId;
55
+ }
56
+ function getFallbackPrice(params) {
57
+ var _ref, _ref2, _ref3, _params$fallback_pric;
58
+ var product = params.product || {};
59
+ return toPriceString((_ref = (_ref2 = (_ref3 = (_params$fallback_pric = params.fallback_price) !== null && _params$fallback_pric !== void 0 ? _params$fallback_pric : product.price) !== null && _ref3 !== void 0 ? _ref3 : product.selling_price) !== null && _ref2 !== void 0 ? _ref2 : product.original_price) !== null && _ref !== void 0 ? _ref : 0);
60
+ }
61
+ function getProductQuantity(product) {
62
+ var _product$num;
63
+ return toPositiveInt((_product$num = product.num) !== null && _product$num !== void 0 ? _product$num : product.quantity, 1);
64
+ }
65
+ function getBundleProductId(bundle) {
66
+ var _bundle$bundle_produc;
67
+ var productId = toFiniteNumber((_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id, NaN);
68
+ if (!Number.isFinite(productId)) return null;
69
+ return productId;
70
+ }
71
+ function getBundleVariantId(bundle) {
72
+ var _bundle$bundle_varian;
73
+ var variantId = toFiniteNumber((_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id, 0);
74
+ if (!Number.isFinite(variantId) || variantId <= 0) return undefined;
75
+ return variantId;
76
+ }
77
+ function getBundleFallbackPrice(bundle) {
78
+ var _ref4, _ref5, _ref6, _bundle$bundle_sellin;
79
+ return toPriceString((_ref4 = (_ref5 = (_ref6 = (_bundle$bundle_sellin = bundle.bundle_selling_price) !== null && _bundle$bundle_sellin !== void 0 ? _bundle$bundle_sellin : bundle.price) !== null && _ref6 !== void 0 ? _ref6 : bundle.original_price) !== null && _ref5 !== void 0 ? _ref5 : bundle.base_price) !== null && _ref4 !== void 0 ? _ref4 : 0);
80
+ }
81
+ function shouldSplitByDuration(duration, start, end) {
82
+ if (!duration) return false;
83
+ if (!start || !end || !end.isAfter(start)) return false;
84
+ var unit = getDurationUnit(duration.type);
85
+ var value = toFiniteNumber(duration.value);
86
+ return !!unit && value > 0;
87
+ }
88
+ function buildTimeSegments(params) {
89
+ var booking = params.booking || {};
90
+ var explicitDatetime = normalizeDateTime(params.datetime);
91
+ var bookingStart = buildBookingDateTime(booking.start_date, booking.start_time);
92
+ var start = bookingStart || explicitDatetime || dayjs();
93
+ var bookingEnd = buildBookingDateTime(booking.end_date, booking.end_time);
94
+ if (!shouldSplitByDuration(params.duration, start, bookingEnd)) {
95
+ return [{
96
+ start: start
97
+ }];
98
+ }
99
+ var unit = getDurationUnit(params.duration.type);
100
+ var value = toFiniteNumber(params.duration.value);
101
+ var segments = [];
102
+ var cursor = start;
103
+ var guard = 0;
104
+ while (cursor.isBefore(bookingEnd) && guard < 10000) {
105
+ var next = cursor.add(value, unit);
106
+ segments.push({
107
+ start: cursor,
108
+ end: next.isBefore(bookingEnd) ? next : bookingEnd !== null && bookingEnd !== void 0 ? bookingEnd : undefined
109
+ });
110
+ cursor = next;
111
+ guard += 1;
112
+ }
113
+ return segments.length ? segments : [{
114
+ start: start
115
+ }];
116
+ }
117
+ function formatTimePoint(datetime) {
118
+ return datetime.format('YYYY-MM-DD HH:mm:ss');
119
+ }
120
+ function buildPriceSegment(params) {
121
+ var timePoint = formatTimePoint(params.segment.start);
122
+ var quotedPrice = params.quotation && params.productId !== null ? params.quotation.getPriceForProduct({
123
+ productId: params.productId,
124
+ variantId: params.variantId,
125
+ datetime: timePoint,
126
+ customer_id: params.customerId
127
+ }) : null;
128
+ var unitPrice = toPriceString(quotedPrice !== null && quotedPrice !== void 0 ? quotedPrice : params.fallbackPrice);
129
+ var quotationShelfId = quotedPrice !== null && params.quotation && params.productId !== null ? params.quotation.getQuotationShelfId({
130
+ productId: params.productId,
131
+ variantId: params.variantId,
132
+ datetime: timePoint,
133
+ customer_id: params.customerId
134
+ }) : 0;
135
+ return {
136
+ start_datetime: timePoint,
137
+ end_datetime: params.segment.end ? formatTimePoint(params.segment.end) : undefined,
138
+ time_point: timePoint,
139
+ unit_price: unitPrice,
140
+ quantity: 1,
141
+ total_price: unitPrice,
142
+ quotation_shelf_id: quotationShelfId,
143
+ source: quotedPrice !== null ? 'quotation' : 'fallback'
144
+ };
145
+ }
146
+ function calculatePriceForProduct(params) {
147
+ var _segments$find;
148
+ var segments = params.segments.map(function (segment) {
149
+ return buildPriceSegment({
150
+ quotation: params.quotation,
151
+ productId: params.productId,
152
+ variantId: params.variantId,
153
+ customerId: params.customerId,
154
+ fallbackPrice: params.fallbackPrice,
155
+ segment: segment
156
+ });
157
+ });
158
+ var unitPrice = segments.reduce(function (total, segment) {
159
+ return total.plus(segment.total_price);
160
+ }, new Decimal(0));
161
+ var totalPrice = unitPrice.times(params.quantity);
162
+ var quotationShelfId = ((_segments$find = segments.find(function (segment) {
163
+ return segment.quotation_shelf_id;
164
+ })) === null || _segments$find === void 0 ? void 0 : _segments$find.quotation_shelf_id) || 0;
165
+ return {
166
+ unitPrice: unitPrice,
167
+ totalPrice: totalPrice,
168
+ quotationShelfId: quotationShelfId,
169
+ segments: segments
170
+ };
171
+ }
172
+ function calculateBundlePrices(params, segments) {
173
+ var _params$product;
174
+ var bundleList = ((_params$product = params.product) === null || _params$product === void 0 ? void 0 : _params$product.product_bundle) || [];
175
+ if (!bundleList.length) return undefined;
176
+ return bundleList.map(function (bundle) {
177
+ var _bundle$bundle_id;
178
+ var productId = getBundleProductId(bundle);
179
+ var variantId = getBundleVariantId(bundle);
180
+ var quantity = getProductQuantity(bundle);
181
+ var price = calculatePriceForProduct({
182
+ quotation: params.quotation,
183
+ productId: productId,
184
+ variantId: variantId,
185
+ customerId: params.customer_id,
186
+ quantity: quantity,
187
+ fallbackPrice: getBundleFallbackPrice(bundle),
188
+ segments: segments
189
+ });
190
+ return {
191
+ bundle_id: (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id,
192
+ group_id: bundle.group_id,
193
+ bundle_group_id: bundle.bundle_group_id,
194
+ bundle_product_id: productId,
195
+ bundle_variant_id: variantId !== null && variantId !== void 0 ? variantId : 0,
196
+ unit_price: price.unitPrice.toDecimalPlaces(2).toFixed(2),
197
+ total_price: price.totalPrice.toDecimalPlaces(2).toFixed(2),
198
+ quantity: quantity,
199
+ quotation_shelf_id: price.quotationShelfId,
200
+ source: price.segments.some(function (segment) {
201
+ return segment.source === 'quotation';
202
+ }) ? 'quotation' : 'fallback',
203
+ segments: price.segments
204
+ };
205
+ });
206
+ }
207
+ export function calculateBaseSalesProductBookingPrice(params) {
208
+ var product = params.product || {};
209
+ var productId = getProductId(product);
210
+ var variantId = getProductVariantId(product);
211
+ var productQuantity = getProductQuantity(product);
212
+ var fallbackPrice = getFallbackPrice(params);
213
+ var timeSegments = buildTimeSegments(params);
214
+ var price = calculatePriceForProduct({
215
+ quotation: params.quotation,
216
+ productId: productId,
217
+ variantId: variantId,
218
+ customerId: params.customer_id,
219
+ quantity: productQuantity,
220
+ fallbackPrice: fallbackPrice,
221
+ segments: timeSegments
222
+ });
223
+ var bundlePrices = calculateBundlePrices(params, timeSegments);
224
+ return _objectSpread({
225
+ product_id: productId,
226
+ product_variant_id: variantId !== null && variantId !== void 0 ? variantId : 0,
227
+ customer_id: params.customer_id,
228
+ unit_price: price.unitPrice.toDecimalPlaces(2).toFixed(2),
229
+ total_price: price.totalPrice.toDecimalPlaces(2).toFixed(2),
230
+ quantity: productQuantity,
231
+ duration: params.duration,
232
+ quotation_shelf_id: price.quotationShelfId,
233
+ segments: price.segments
234
+ }, bundlePrices ? {
235
+ product_bundle: bundlePrices
236
+ } : {});
237
+ }
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  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; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  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); }
7
+ import { buildManualProductDiscountItem, mergeManualProductDiscountIntoList, resolveManualDiscountOriginTotal, resolveManualDiscountReasonFromSources, shouldBuildManualProductDiscount } from "../../../modules/Order/utils/manualProductDiscount";
7
8
  function toNumber(value) {
8
9
  var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
9
10
  var parsedValue = Number(value);
@@ -43,9 +44,19 @@ function normalizeOptionItems(optionItems) {
43
44
  });
44
45
  }
45
46
  function normalizeBundleItems(bundleItems) {
47
+ var preferPriceField = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
46
48
  if (!Array.isArray(bundleItems)) return [];
47
49
  return bundleItems.map(function (bundleItem) {
50
+ var _ref2, _ref3, _ref4, _bundleItem$price, _ref5, _ref6, _ref7, _bundleItem$bundle_se, _bundleItem$num, _bundleItem$quantity, _bundleItem$price2, _ref8, _ref9, _bundleItem$original_;
51
+ var unitSelling = preferPriceField ? (_ref2 = (_ref3 = (_ref4 = (_bundleItem$price = bundleItem.price) !== null && _bundleItem$price !== void 0 ? _bundleItem$price : bundleItem.bundle_selling_price) !== null && _ref4 !== void 0 ? _ref4 : bundleItem.custom_price) !== null && _ref3 !== void 0 ? _ref3 : bundleItem.product_price) !== null && _ref2 !== void 0 ? _ref2 : '0' : (_ref5 = (_ref6 = (_ref7 = (_bundleItem$bundle_se = bundleItem.bundle_selling_price) !== null && _bundleItem$bundle_se !== void 0 ? _bundleItem$bundle_se : bundleItem.price) !== null && _ref7 !== void 0 ? _ref7 : bundleItem.custom_price) !== null && _ref6 !== void 0 ? _ref6 : bundleItem.product_price) !== null && _ref5 !== void 0 ? _ref5 : '0';
52
+ var unitStr = toPriceString(unitSelling, '0.00');
53
+ var num = toSafePositiveInt((_bundleItem$num = bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.num) !== null && _bundleItem$num !== void 0 ? _bundleItem$num : bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.quantity, 1);
48
54
  return _objectSpread(_objectSpread({}, bundleItem), {}, {
55
+ num: num,
56
+ quantity: (_bundleItem$quantity = bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.quantity) !== null && _bundleItem$quantity !== void 0 ? _bundleItem$quantity : num,
57
+ price: (_bundleItem$price2 = bundleItem.price) !== null && _bundleItem$price2 !== void 0 ? _bundleItem$price2 : unitStr,
58
+ bundle_selling_price: unitStr,
59
+ original_price: (_ref8 = (_ref9 = (_bundleItem$original_ = bundleItem.original_price) !== null && _bundleItem$original_ !== void 0 ? _bundleItem$original_ : bundleItem.product_price) !== null && _ref9 !== void 0 ? _ref9 : bundleItem.price) !== null && _ref8 !== void 0 ? _ref8 : unitStr,
49
60
  option: normalizeOptionItems(bundleItem === null || bundleItem === void 0 ? void 0 : bundleItem.option)
50
61
  });
51
62
  });
@@ -64,23 +75,55 @@ function findVariantById(origin, variantId) {
64
75
  * 注意:这里不生成 identity,缺省时由 OrderModule 自动补齐。
65
76
  */
66
77
  export function transformBaseProductToOrderProduct(params) {
67
- var _ref2, _ref3, _ref4, _payload$product_id, _ref5, _ref6, _payload$product_vari, _payload$_origin, _payload$_origin2, _ref7, _findVariantById, _ref8, _ref9, _ref10, _ref11, _ref12, _ref13, _ref14, _payload$price, _ref15, _payload$option, _payload$bundle, _payload$unique_ident, _payload$quantity, _ref16, _ref17, _payload$tax_fee, _ref18, _ref19, _payload$is_charge_ta;
78
+ var _ref10, _ref11, _ref12, _payload$product_id, _ref13, _ref14, _payload$product_vari, _payload$_origin, _payload$_origin2, _ref15, _findVariantById, _ref16, _ref17, _ref18, _ref19, _ref20, _ref21, _ref22, _payload$price, _ref23, _payload$line_total, _payload$_extend, _ref24, _payload$option, _payload$bundle, _payload$quantity, _payload$_extend2, _extend, _extend2, _ref25, _ref26, _origin$base_price, _ref27, _ref28, _payload$line_total2, _payload$_extend3, _payload$_extend4, _extend3, _payload$_extend5, _payload$_extend6, _ref29, _ref30, _payload$tax_fee, _ref31, _ref32, _payload$is_charge_ta;
68
79
  var payload = params.payload,
69
80
  _params$fallbackProdu = params.fallbackProductId,
70
81
  fallbackProductId = _params$fallbackProdu === void 0 ? null : _params$fallbackProdu;
71
82
  if (!payload || _typeof(payload) !== 'object') return null;
72
83
  var sourceProduct = params.sourceProduct || params.sourceItem || {};
73
- var productId = toProductId((_ref2 = (_ref3 = (_ref4 = (_payload$product_id = payload.product_id) !== null && _payload$product_id !== void 0 ? _payload$product_id : payload.id) !== null && _ref4 !== void 0 ? _ref4 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_id) !== null && _ref3 !== void 0 ? _ref3 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id) !== null && _ref2 !== void 0 ? _ref2 : fallbackProductId);
84
+ var productId = toProductId((_ref10 = (_ref11 = (_ref12 = (_payload$product_id = payload.product_id) !== null && _payload$product_id !== void 0 ? _payload$product_id : payload.id) !== null && _ref12 !== void 0 ? _ref12 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_id) !== null && _ref11 !== void 0 ? _ref11 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.id) !== null && _ref10 !== void 0 ? _ref10 : fallbackProductId);
74
85
  if (productId === null) return null;
75
- var productVariantId = toNumber((_ref5 = (_ref6 = (_payload$product_vari = payload.product_variant_id) !== null && _payload$product_vari !== void 0 ? _payload$product_vari : payload.variant_id) !== null && _ref6 !== void 0 ? _ref6 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_variant_id) !== null && _ref5 !== void 0 ? _ref5 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.variant_id, 0);
86
+ var productVariantId = toNumber((_ref13 = (_ref14 = (_payload$product_vari = payload.product_variant_id) !== null && _payload$product_vari !== void 0 ? _payload$product_vari : payload.variant_id) !== null && _ref14 !== void 0 ? _ref14 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.product_variant_id) !== null && _ref13 !== void 0 ? _ref13 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.variant_id, 0);
76
87
  var callbackOrigin = payload.origin || ((_payload$_origin = payload._origin) === null || _payload$_origin === void 0 ? void 0 : _payload$_origin.sourceProduct) || ((_payload$_origin2 = payload._origin) === null || _payload$_origin2 === void 0 ? void 0 : _payload$_origin2.sourceItem) || payload._origin || {};
77
88
  var origin = _objectSpread(_objectSpread({}, sourceProduct || {}), callbackOrigin || {});
78
- var matchedVariant = (_ref7 = (_findVariantById = findVariantById(callbackOrigin, productVariantId)) !== null && _findVariantById !== void 0 ? _findVariantById : findVariantById(sourceProduct, productVariantId)) !== null && _ref7 !== void 0 ? _ref7 : findVariantById(origin, productVariantId);
79
- var sourceProductPrice = toPriceString((_ref8 = (_ref9 = (_ref10 = (_ref11 = (_ref12 = (_ref13 = (_ref14 = (_payload$price = payload.price) !== null && _payload$price !== void 0 ? _payload$price : payload.selling_price) !== null && _ref14 !== void 0 ? _ref14 : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.price) !== null && _ref13 !== void 0 ? _ref13 : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.base_price) !== null && _ref12 !== void 0 ? _ref12 : origin === null || origin === void 0 ? void 0 : origin.price) !== null && _ref11 !== void 0 ? _ref11 : origin === null || origin === void 0 ? void 0 : origin.base_price) !== null && _ref10 !== void 0 ? _ref10 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _ref9 !== void 0 ? _ref9 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.selling_price) !== null && _ref8 !== void 0 ? _ref8 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price, '0.00');
80
- var productOptionItem = normalizeOptionItems((_ref15 = (_payload$option = payload.option) !== null && _payload$option !== void 0 ? _payload$option : payload.options) !== null && _ref15 !== void 0 ? _ref15 : payload.product_option_item);
81
- var productBundle = normalizeBundleItems((_payload$bundle = payload.bundle) !== null && _payload$bundle !== void 0 ? _payload$bundle : payload.product_bundle);
82
- var uniqueIdentificationNumber = (_payload$unique_ident = payload.unique_identification_number) !== null && _payload$unique_ident !== void 0 ? _payload$unique_ident : payload.unique;
83
- var metadata = {
89
+ var matchedVariant = (_ref15 = (_findVariantById = findVariantById(callbackOrigin, productVariantId)) !== null && _findVariantById !== void 0 ? _findVariantById : findVariantById(sourceProduct, productVariantId)) !== null && _ref15 !== void 0 ? _ref15 : findVariantById(origin, productVariantId);
90
+ var sourceProductPrice = toPriceString((_ref16 = (_ref17 = (_ref18 = (_ref19 = (_ref20 = (_ref21 = (_ref22 = (_payload$price = payload.price) !== null && _payload$price !== void 0 ? _payload$price : payload.selling_price) !== null && _ref22 !== void 0 ? _ref22 : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.price) !== null && _ref21 !== void 0 ? _ref21 : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.base_price) !== null && _ref20 !== void 0 ? _ref20 : origin === null || origin === void 0 ? void 0 : origin.price) !== null && _ref19 !== void 0 ? _ref19 : origin === null || origin === void 0 ? void 0 : origin.base_price) !== null && _ref18 !== void 0 ? _ref18 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price) !== null && _ref17 !== void 0 ? _ref17 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.selling_price) !== null && _ref16 !== void 0 ? _ref16 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price, '0.00');
91
+ var lineCompositeTotal = toPriceString((_ref23 = (_payload$line_total = payload.line_total) !== null && _payload$line_total !== void 0 ? _payload$line_total : payload.total) !== null && _ref23 !== void 0 ? _ref23 : (_payload$_extend = payload._extend) === null || _payload$_extend === void 0 ? void 0 : _payload$_extend.total, sourceProductPrice);
92
+ var hasPriceOverride = payload.price_override !== undefined && payload.price_override !== null && payload.price_override !== '';
93
+ var productOptionItem = normalizeOptionItems((_ref24 = (_payload$option = payload.option) !== null && _payload$option !== void 0 ? _payload$option : payload.options) !== null && _ref24 !== void 0 ? _ref24 : payload.product_option_item);
94
+ var productBundle = normalizeBundleItems((_payload$bundle = payload.bundle) !== null && _payload$bundle !== void 0 ? _payload$bundle : payload.product_bundle, hasPriceOverride);
95
+ // `payload.unique` 是业务侧商品/票务标识,可能在连续加同一商品时重复;
96
+ // 行级唯一值只接受显式协议字段,缺省交给 OrderModule 生成。
97
+ var uniqueIdentificationNumber = payload.unique_identification_number;
98
+ var resolvedQuantity = toSafePositiveInt((_payload$quantity = payload.quantity) !== null && _payload$quantity !== void 0 ? _payload$quantity : payload.num, 1);
99
+ var originTotal = resolveManualDiscountOriginTotal({
100
+ originTotal: payload.origin_total,
101
+ extendOriginTotal: (_payload$_extend2 = payload._extend) === null || _payload$_extend2 === void 0 ? void 0 : _payload$_extend2.origin_total,
102
+ originExtendOriginTotal: origin === null || origin === void 0 || (_extend = origin._extend) === null || _extend === void 0 ? void 0 : _extend.origin_total,
103
+ sourceExtendOriginTotal: sourceProduct === null || sourceProduct === void 0 || (_extend2 = sourceProduct._extend) === null || _extend2 === void 0 ? void 0 : _extend2.origin_total,
104
+ catalogUnitPrice: (_ref25 = (_ref26 = (_origin$base_price = origin === null || origin === void 0 ? void 0 : origin.base_price) !== null && _origin$base_price !== void 0 ? _origin$base_price : origin === null || origin === void 0 ? void 0 : origin.price) !== null && _ref26 !== void 0 ? _ref26 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.base_price) !== null && _ref25 !== void 0 ? _ref25 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.price,
105
+ quantity: resolvedQuantity
106
+ });
107
+ var sellingTotal = Number((_ref27 = (_ref28 = (_payload$line_total2 = payload.line_total) !== null && _payload$line_total2 !== void 0 ? _payload$line_total2 : payload.total) !== null && _ref28 !== void 0 ? _ref28 : (_payload$_extend3 = payload._extend) === null || _payload$_extend3 === void 0 ? void 0 : _payload$_extend3.total) !== null && _ref27 !== void 0 ? _ref27 : lineCompositeTotal);
108
+ var discountReason = resolveManualDiscountReasonFromSources({
109
+ discountReason: payload.discount_reason,
110
+ extendDiscountReason: (_payload$_extend4 = payload._extend) === null || _payload$_extend4 === void 0 ? void 0 : _payload$_extend4.discount_reason,
111
+ originExtendDiscountReason: origin === null || origin === void 0 || (_extend3 = origin._extend) === null || _extend3 === void 0 ? void 0 : _extend3.discount_reason
112
+ });
113
+ var lineOriginalPrice = hasPriceOverride && Number.isFinite(originTotal) ? toPriceString(originTotal) : lineCompositeTotal;
114
+ var manualDiscountList = shouldBuildManualProductDiscount({
115
+ hasPriceOverride: hasPriceOverride,
116
+ originTotal: originTotal,
117
+ sellingTotal: sellingTotal
118
+ }) ? mergeManualProductDiscountIntoList(payload.discount_list, buildManualProductDiscountItem({
119
+ originTotal: Number.isFinite(originTotal) ? originTotal : Number(lineOriginalPrice),
120
+ sellingTotal: Number.isFinite(sellingTotal) ? sellingTotal : Number(lineCompositeTotal),
121
+ quantity: resolvedQuantity,
122
+ message: discountReason,
123
+ discountway: (_payload$_extend5 = payload._extend) === null || _payload$_extend5 === void 0 ? void 0 : _payload$_extend5.discountway,
124
+ discount_per: (_payload$_extend6 = payload._extend) === null || _payload$_extend6 === void 0 ? void 0 : _payload$_extend6.discount_per
125
+ })) : payload.discount_list || [];
126
+ var metadata = _objectSpread(_objectSpread({
84
127
  unique: payload.unique,
85
128
  session: payload.session,
86
129
  form: payload.form,
@@ -91,8 +134,15 @@ export function transformBaseProductToOrderProduct(params) {
91
134
  policy_id: payload.policy_id,
92
135
  source_shop_id: payload.source_shop_id,
93
136
  origin: origin,
94
- source_product_price: sourceProductPrice
95
- };
137
+ source_product_price: sourceProductPrice,
138
+ main_product_selling_price: sourceProductPrice,
139
+ main_product_original_price: sourceProductPrice
140
+ }, hasPriceOverride ? {
141
+ price_override: String(payload.price_override),
142
+ is_manual_discount: 1
143
+ } : {}), payload.bundle_edit !== undefined ? {
144
+ bundle_edit: payload.bundle_edit
145
+ } : {});
96
146
  if (uniqueIdentificationNumber) {
97
147
  metadata.unique_identification_number = String(uniqueIdentificationNumber);
98
148
  }
@@ -100,13 +150,15 @@ export function transformBaseProductToOrderProduct(params) {
100
150
  product_id: productId,
101
151
  product_variant_id: productVariantId,
102
152
  unique_identification_number: uniqueIdentificationNumber ? String(uniqueIdentificationNumber) : undefined,
103
- num: toSafePositiveInt((_payload$quantity = payload.quantity) !== null && _payload$quantity !== void 0 ? _payload$quantity : payload.num, 1),
153
+ num: resolvedQuantity,
104
154
  product_option_item: productOptionItem,
105
155
  product_bundle: productBundle,
106
- selling_price: sourceProductPrice,
107
- original_price: sourceProductPrice,
108
- tax_fee: toPriceString((_ref16 = (_ref17 = (_payload$tax_fee = payload.tax_fee) !== null && _payload$tax_fee !== void 0 ? _payload$tax_fee : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.tax_fee) !== null && _ref17 !== void 0 ? _ref17 : origin === null || origin === void 0 ? void 0 : origin.tax_fee) !== null && _ref16 !== void 0 ? _ref16 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.tax_fee, '0.00'),
109
- is_charge_tax: toNumber((_ref18 = (_ref19 = (_payload$is_charge_ta = payload.is_charge_tax) !== null && _payload$is_charge_ta !== void 0 ? _payload$is_charge_ta : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.is_charge_tax) !== null && _ref19 !== void 0 ? _ref19 : origin === null || origin === void 0 ? void 0 : origin.is_charge_tax) !== null && _ref18 !== void 0 ? _ref18 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.is_charge_tax, 0),
156
+ discount_list: manualDiscountList,
157
+ // 折后行价由 normalizeOrderProduct 按 main + bundle 合成;手动改价时 bundle 已为分摊后单价
158
+ selling_price: lineCompositeTotal,
159
+ original_price: lineOriginalPrice,
160
+ tax_fee: toPriceString((_ref29 = (_ref30 = (_payload$tax_fee = payload.tax_fee) !== null && _payload$tax_fee !== void 0 ? _payload$tax_fee : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.tax_fee) !== null && _ref30 !== void 0 ? _ref30 : origin === null || origin === void 0 ? void 0 : origin.tax_fee) !== null && _ref29 !== void 0 ? _ref29 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.tax_fee, '0.00'),
161
+ is_charge_tax: toNumber((_ref31 = (_ref32 = (_payload$is_charge_ta = payload.is_charge_tax) !== null && _payload$is_charge_ta !== void 0 ? _payload$is_charge_ta : matchedVariant === null || matchedVariant === void 0 ? void 0 : matchedVariant.is_charge_tax) !== null && _ref32 !== void 0 ? _ref32 : origin === null || origin === void 0 ? void 0 : origin.is_charge_tax) !== null && _ref31 !== void 0 ? _ref31 : sourceProduct === null || sourceProduct === void 0 ? void 0 : sourceProduct.is_charge_tax, 0),
110
162
  metadata: metadata,
111
163
  note: payload.note != null ? String(payload.note) : '',
112
164
  _origin: _objectSpread(_objectSpread({}, sourceProduct || {}), {}, {
@@ -5,7 +5,8 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  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); }
7
7
  import Decimal from 'decimal.js';
8
- import { composeLinePrice, createUuidV4, sumOptionUnitPrice } from "../../modules/Order/utils";
8
+ import { composeLinePrice, createUuidV4, resolveManualOverrideLineOriginalPrice, sumOptionUnitPrice } from "../../modules/Order/utils";
9
+ import { ensureManualProductDiscountList } from "../../modules/Order/utils/manualProductDiscount";
9
10
 
10
11
  /**
11
12
  * 构建金额全为 0 的空 summary。
@@ -106,17 +107,42 @@ export function isSkuOnlyDeleteIdentity(x) {
106
107
  * - 因此多次 normalize 不会重复叠加 option/bundle。
107
108
  */
108
109
  export function normalizeOrderProduct(product) {
109
- var _product$metadata, _metadata$origin, _variantList$find, _product$is_charge_ta;
110
+ var _product$metadata, _metadata$origin, _metadata$origin2, _variantList$find, _product$is_charge_ta;
110
111
  var metadata = _objectSpread({}, product.metadata || {});
111
112
  // 不透明 identity 契约:每条订单行必须带 identity_key。
112
113
  // 调用方未传时由 SDK 自动生成 UUID,后续 update/remove 只做严格比对,避免猜测合成 key。
113
114
  var resolvedIdentityKey = (_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.unique_identification_number ? String(product.metadata.unique_identification_number) : product.unique_identification_number && String(product.unique_identification_number).length > 0 ? String(product.unique_identification_number) : product.identity_key && String(product.identity_key).length > 0 ? String(product.identity_key) : createUuidV4();
114
115
  metadata.unique_identification_number = resolvedIdentityKey;
115
- var normalizedBundle = (product.product_bundle || []).map(function (item) {
116
- var _ref2, _item$bundle_selling_, _ref3, _ref4, _item$price2, _ref5, _item$price_type, _ref6, _item$price_type_ext;
116
+ var priceOverride = metadata.price_override;
117
+ var originOtherBundle = (_metadata$origin = metadata.origin) === null || _metadata$origin === void 0 || (_metadata$origin = _metadata$origin._extend) === null || _metadata$origin === void 0 || (_metadata$origin = _metadata$origin.other) === null || _metadata$origin === void 0 ? void 0 : _metadata$origin.bundle;
118
+ var bundleInput = product.product_bundle || [];
119
+ if (priceOverride !== undefined && priceOverride !== null && priceOverride !== '' && Array.isArray(originOtherBundle) && originOtherBundle.length > 0) {
120
+ var priceById = new Map();
121
+ originOtherBundle.forEach(function (item) {
122
+ var _item$price2;
123
+ if ((item === null || item === void 0 ? void 0 : item.id) == null) return;
124
+ var unit = (_item$price2 = item.price) !== null && _item$price2 !== void 0 ? _item$price2 : item.bundle_selling_price;
125
+ if (unit === undefined || unit === null) return;
126
+ priceById.set(String(item.id), String(unit));
127
+ });
128
+ var base = Array.isArray(bundleInput) && bundleInput.length > 0 ? bundleInput : originOtherBundle;
129
+ bundleInput = base.map(function (item) {
130
+ var unit = priceById.get(String(item === null || item === void 0 ? void 0 : item.id));
131
+ if (unit === undefined) return item;
132
+ return _objectSpread(_objectSpread({}, item), {}, {
133
+ price: unit,
134
+ bundle_selling_price: unit
135
+ });
136
+ });
137
+ }
138
+ var normalizedBundle = bundleInput.map(function (item) {
139
+ var _item$bundle_id2, _item$bundle_product_, _item$bundle_group_id, _ref2, _item$bundle_selling_, _ref3, _ref4, _item$price3, _ref5, _item$price_type, _ref6, _item$price_type_ext;
117
140
  return _objectSpread(_objectSpread({}, item), {}, {
141
+ bundle_id: (_item$bundle_id2 = item.bundle_id) !== null && _item$bundle_id2 !== void 0 ? _item$bundle_id2 : item.id,
142
+ bundle_product_id: (_item$bundle_product_ = item.bundle_product_id) !== null && _item$bundle_product_ !== void 0 ? _item$bundle_product_ : item._bundle_product_id,
143
+ bundle_group_id: (_item$bundle_group_id = item.bundle_group_id) !== null && _item$bundle_group_id !== void 0 ? _item$bundle_group_id : item.group_id,
118
144
  bundle_selling_price: (_ref2 = (_item$bundle_selling_ = item.bundle_selling_price) !== null && _item$bundle_selling_ !== void 0 ? _item$bundle_selling_ : item.price) !== null && _ref2 !== void 0 ? _ref2 : '0.00',
119
- price: (_ref3 = (_ref4 = (_item$price2 = item.price) !== null && _item$price2 !== void 0 ? _item$price2 : item.custom_price) !== null && _ref4 !== void 0 ? _ref4 : item.bundle_selling_price) !== null && _ref3 !== void 0 ? _ref3 : '0.00',
145
+ price: (_ref3 = (_ref4 = (_item$price3 = item.price) !== null && _item$price3 !== void 0 ? _item$price3 : item.custom_price) !== null && _ref4 !== void 0 ? _ref4 : item.bundle_selling_price) !== null && _ref3 !== void 0 ? _ref3 : '0.00',
120
146
  price_type: (_ref5 = (_item$price_type = item.price_type) !== null && _item$price_type !== void 0 ? _item$price_type : item.custom_price_type) !== null && _ref5 !== void 0 ? _ref5 : '',
121
147
  price_type_ext: (_ref6 = (_item$price_type_ext = item.price_type_ext) !== null && _item$price_type_ext !== void 0 ? _item$price_type_ext : item.custom_price_type_ext) !== null && _ref6 !== void 0 ? _ref6 : ''
122
148
  });
@@ -134,7 +160,7 @@ export function normalizeOrderProduct(product) {
134
160
  // 6) 入参 selling_price(最末兜底,新添加路径 caller 只给 selling_price)
135
161
  var isV2 = metadata.price_schema_version === 2 || metadata.price_schema_version === '2';
136
162
  var variantId = Number(product.product_variant_id || 0);
137
- var variantList = variantId ? metadata === null || metadata === void 0 || (_metadata$origin = metadata.origin) === null || _metadata$origin === void 0 ? void 0 : _metadata$origin.variant : null;
163
+ var variantList = variantId ? metadata === null || metadata === void 0 || (_metadata$origin2 = metadata.origin) === null || _metadata$origin2 === void 0 ? void 0 : _metadata$origin2.variant : null;
138
164
  var variantPrice = Array.isArray(variantList) ? (_variantList$find = variantList.find(function (v) {
139
165
  return Number(v === null || v === void 0 ? void 0 : v.id) === variantId;
140
166
  })) === null || _variantList$find === void 0 ? void 0 : _variantList$find.price : undefined;
@@ -204,6 +230,18 @@ export function normalizeOrderProduct(product) {
204
230
  bundle: normalizedBundle,
205
231
  useOriginalBundle: true
206
232
  });
233
+ var finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
234
+ num: product.num,
235
+ metadata: metadata,
236
+ lineOriginalPrice: product.original_price
237
+ }, composedOriginalPrice);
238
+ var discountList = ensureManualProductDiscountList({
239
+ discountList: product.discount_list,
240
+ metadata: metadata,
241
+ originalPrice: finalOriginalPrice,
242
+ sellingPrice: composedSellingPrice,
243
+ quantity: getSafeProductNum(product.num)
244
+ });
207
245
  return {
208
246
  order_detail_id: product.order_detail_id || null,
209
247
  product_id: product.product_id,
@@ -211,10 +249,10 @@ export function normalizeOrderProduct(product) {
211
249
  product_variant_id: product.product_variant_id,
212
250
  product_option_item: normalizedOptions,
213
251
  selling_price: composedSellingPrice,
214
- original_price: composedOriginalPrice,
252
+ original_price: finalOriginalPrice,
215
253
  tax_fee: product.tax_fee || '0.00',
216
254
  is_charge_tax: (_product$is_charge_ta = product.is_charge_tax) !== null && _product$is_charge_ta !== void 0 ? _product$is_charge_ta : 0,
217
- discount_list: product.discount_list || [],
255
+ discount_list: discountList,
218
256
  product_bundle: normalizedBundle,
219
257
  metadata: metadata,
220
258
  note: product.note != null ? String(product.note) : ''
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 5 | 3 | 4 | 6;
314
+ weekNum: 0 | 1 | 2 | 6 | 3 | 5 | 4;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;