@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
@@ -1,10 +1,9 @@
1
1
  var _excluded = ["unique_identification_number"],
2
- _excluded2 = ["num", "product_option_item", "surcharge_fee"],
3
- _excluded3 = ["_extend", "relation_id", "table_form_id", "resource_id", "summary", "lastOrderInfo", "paid_amount", "shop_id", "shop_note", "shop_service_type", "start_time", "customer", "shop_full_order_number", "tax_fee", "total_amount", "total_refund_amount", "create_date", "holder_id"],
2
+ _excluded2 = ["num", "product_option_item", "surcharge_fee", "discount_amount", "discount_type", "discountway", "product_discount_reason", "discount_per"],
3
+ _excluded3 = ["_extend", "relation_id", "table_form_id", "resource_id", "summary", "lastOrderInfo", "paid_amount", "shop_id", "shop_note", "shop_service_type", "start_time", "customer", "discount_list", "tax_fee", "total_amount", "total_refund_amount", "create_date", "holder_id"],
4
4
  _excluded4 = ["collect_pax", "table_occupancy_duration"];
5
5
  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; }
6
6
  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; }
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
7
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
9
8
  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."); }
10
9
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
@@ -14,6 +13,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
14
13
  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; }
15
14
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
16
15
  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); }
16
+ 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); }
17
17
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
18
18
  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); }
19
19
  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; }
@@ -113,14 +113,165 @@ export function sumOptionUnitPrice(options) {
113
113
  *
114
114
  * 导出为纯函数方便单测直接驱动钩子,不依赖 OrderModule 实例。
115
115
  */
116
+
117
+ /** Rules calcDiscount 用手动价标记;undefined 表示交给 Rules 用 total/origin_total 推断 */
118
+ export function resolveRulesManualDiscountFlag(metadata) {
119
+ if (!metadata) return undefined;
120
+ if (metadata.is_manual_discount === true || metadata.is_manual_discount === 1) {
121
+ return true;
122
+ }
123
+ var priceOverride = metadata.price_override;
124
+ if (priceOverride !== undefined && priceOverride !== null && priceOverride !== '') {
125
+ return true;
126
+ }
127
+ return undefined;
128
+ }
129
+ function normalizeOrderProductDiscountAmount(amount) {
130
+ if (amount === undefined || amount === null) return undefined;
131
+ return String(amount);
132
+ }
133
+
134
+ /**
135
+ * 商品行折扣只保留后端 OrderProductDiscountItem 协议字段。
136
+ * Rules/券计算过程中的 `_num`、`config` 等运行态字段不应进入 tempOrder 或提交 payload。
137
+ */
138
+ export function normalizeOrderProductDiscountList(discountList) {
139
+ if (!Array.isArray(discountList)) return [];
140
+ return discountList.filter(function (item) {
141
+ return !!item && _typeof(item) === 'object';
142
+ }).map(function (item) {
143
+ var normalized = {
144
+ discount_id: Number.isFinite(Number(item.discount_id)) ? Number(item.discount_id) : 0
145
+ };
146
+ if (item.order_discount_id === null) {
147
+ normalized.order_discount_id = null;
148
+ } else if (item.order_discount_id !== undefined) {
149
+ var orderDiscountId = Number(item.order_discount_id);
150
+ if (Number.isFinite(orderDiscountId)) {
151
+ normalized.order_discount_id = orderDiscountId;
152
+ }
153
+ }
154
+ if (item.type !== undefined) normalized.type = item.type;
155
+ var amount = normalizeOrderProductDiscountAmount(item.amount);
156
+ if (amount !== undefined) normalized.amount = amount;
157
+ if (item.discount && _typeof(item.discount) === 'object') {
158
+ normalized.discount = _objectSpread({}, item.discount);
159
+ }
160
+ if (item.metadata === null) {
161
+ normalized.metadata = null;
162
+ } else if (item.metadata && _typeof(item.metadata) === 'object') {
163
+ normalized.metadata = _objectSpread({}, item.metadata);
164
+ }
165
+ return normalized;
166
+ });
167
+ }
168
+
169
+ /**
170
+ * 手动改价(price_override)时行级 original_price(composite 单价):
171
+ * 购物车划线价应对齐 metadata.origin._extend.origin_total(改价前单价 composite,如 40),
172
+ * 而非 bundle 子项 catalog 原价合成的 composedOriginalPrice(如 30)。
173
+ *
174
+ * origin_total 与 SkuDetailModal / cacheItem._extend 一致,为单价语义,不再除以 num。
175
+ */
176
+ export function resolveManualOverrideLineOriginalPrice(params, fallbackCompositeOriginal) {
177
+ var _metadata$origin;
178
+ var metadata = params.metadata || {};
179
+ var priceOverride = metadata.price_override;
180
+ if (priceOverride === undefined || priceOverride === null || priceOverride === '') {
181
+ return fallbackCompositeOriginal;
182
+ }
183
+ var refTotal = (_metadata$origin = metadata.origin) === null || _metadata$origin === void 0 || (_metadata$origin = _metadata$origin._extend) === null || _metadata$origin === void 0 ? void 0 : _metadata$origin.origin_total;
184
+ if (refTotal !== undefined && refTotal !== null && refTotal !== '') {
185
+ var parsed = Number(refTotal);
186
+ if (Number.isFinite(parsed)) {
187
+ return new Decimal(parsed).toDecimalPlaces(2).toFixed(2);
188
+ }
189
+ }
190
+ var lineOriginal = params.lineOriginalPrice;
191
+ if (lineOriginal !== undefined && lineOriginal !== null && lineOriginal !== '') {
192
+ var parsedLine = Number(lineOriginal);
193
+ var parsedFallback = Number(fallbackCompositeOriginal);
194
+ if (Number.isFinite(parsedLine) && Number.isFinite(parsedFallback) && parsedLine > parsedFallback) {
195
+ return new Decimal(parsedLine).toDecimalPlaces(2).toFixed(2);
196
+ }
197
+ }
198
+ return fallbackCompositeOriginal;
199
+ }
200
+
201
+ /**
202
+ * 计算商品行「每单位有效折扣」:discount_list 合计 + 被 Rules 剥离但仍 inPromotion 的差额。
203
+ *
204
+ * Rules.calcDiscount 会把 type=promotion 从 discount_list 去掉,但 metadata._promotion 仍保留;
205
+ * applyProductDiscountPrices 必须回读 _promotion,否则抬价/降价都会在第二步被 source 原价覆盖。
206
+ *
207
+ * @example
208
+ * resolveEffectivePerUnitDiscount({ metadata: { _promotion: { inPromotion: true, originalPrice: 1, finalPrice: 5 } }, discount_list: [] });
209
+ * // => -4
210
+ */
211
+ export function resolveEffectivePerUnitDiscount(product) {
212
+ var discountList = Array.isArray(product === null || product === void 0 ? void 0 : product.discount_list) ? product.discount_list : [];
213
+ var fromList = discountList.reduce(function (sum, discount) {
214
+ return sum + Number((discount === null || discount === void 0 ? void 0 : discount.amount) || 0);
215
+ }, 0);
216
+ var hasPromoDiscountItem = discountList.some(function (item) {
217
+ return (item === null || item === void 0 ? void 0 : item.type) === 'promotion';
218
+ });
219
+ if (hasPromoDiscountItem) return fromList;
220
+ var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
221
+ var optionSum = sumOptionUnitPrice(product === null || product === void 0 ? void 0 : product.product_option_item).toNumber();
222
+
223
+ // applyPromotion 写价后、Rules 剥离 promotion discount 的兜底
224
+ if (metadata.source_product_price != null && metadata.main_product_selling_price != null) {
225
+ var source = Number(metadata.source_product_price);
226
+ var selling = Number(metadata.main_product_selling_price) - optionSum;
227
+ if (Number.isFinite(source) && Number.isFinite(selling) && source !== selling) {
228
+ return fromList + (source - selling);
229
+ }
230
+ }
231
+ var promo = metadata._promotion;
232
+ if ((promo === null || promo === void 0 ? void 0 : promo.inPromotion) !== true) return fromList;
233
+ var originalPrice = Number(promo.originalPrice);
234
+ var finalPrice = Number(promo.finalPrice);
235
+ if (!Number.isFinite(originalPrice) || !Number.isFinite(finalPrice)) return fromList;
236
+ return fromList + (originalPrice - finalPrice);
237
+ }
116
238
  export function createDefaultOrderRulesHooks() {
117
239
  var toUnitPriceString = function toUnitPriceString(totalLike, num) {
118
240
  var effectiveNum = Number(num) > 0 ? Number(num) : 1;
119
241
  return new Decimal(Number(totalLike) || 0).dividedBy(effectiveNum).toDecimalPlaces(2).toString();
120
242
  };
243
+ var getBundleIdentity = function getBundleIdentity(bundle) {
244
+ var _ref3, _bundle$bundle_id, _ref4, _ref5, _bundle$bundle_produc, _ref6, _ref7, _bundle$bundle_varian, _ref8, _bundle$bundle_group_;
245
+ return [(_ref3 = (_bundle$bundle_id = bundle.bundle_id) !== null && _bundle$bundle_id !== void 0 ? _bundle$bundle_id : bundle.id) !== null && _ref3 !== void 0 ? _ref3 : '', (_ref4 = (_ref5 = (_bundle$bundle_produc = bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle._bundle_product_id) !== null && _ref5 !== void 0 ? _ref5 : bundle.product_id) !== null && _ref4 !== void 0 ? _ref4 : '', (_ref6 = (_ref7 = (_bundle$bundle_varian = bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle.variant_id) !== null && _ref7 !== void 0 ? _ref7 : bundle.product_variant_id) !== null && _ref6 !== void 0 ? _ref6 : 0, (_ref8 = (_bundle$bundle_group_ = bundle.bundle_group_id) !== null && _bundle$bundle_group_ !== void 0 ? _bundle$bundle_group_ : bundle.group_id) !== null && _ref8 !== void 0 ? _ref8 : ''].join('|');
246
+ };
247
+ var mergeRulesBundlePrices = function mergeRulesBundlePrices(currentBundle, rulesBundle) {
248
+ if (!Array.isArray(rulesBundle)) return rulesBundle;
249
+ var currentByIdentity = new Map();
250
+ (currentBundle || []).forEach(function (bundle) {
251
+ if (!bundle || _typeof(bundle) !== 'object') return;
252
+ currentByIdentity.set(getBundleIdentity(bundle), bundle);
253
+ });
254
+ return rulesBundle.map(function (bundle) {
255
+ var _bundle$price_type_ex, _ref9, _ref10, _current$price, _ref11, _ref12, _ref13, _current$original_pri;
256
+ if (!bundle || _typeof(bundle) !== 'object') return bundle;
257
+ var current = currentByIdentity.get(getBundleIdentity(bundle));
258
+ if (!current) return bundle;
259
+ var isProductPriceBundle = ((_bundle$price_type_ex = bundle.price_type_ext) !== null && _bundle$price_type_ex !== void 0 ? _bundle$price_type_ex : current.price_type_ext) === 'product_price';
260
+ if (!isProductPriceBundle) return bundle;
261
+ var sourcePrice = (_ref9 = (_ref10 = (_current$price = current.price) !== null && _current$price !== void 0 ? _current$price : current.custom_price) !== null && _ref10 !== void 0 ? _ref10 : current.original_price) !== null && _ref9 !== void 0 ? _ref9 : current.bundle_selling_price;
262
+ var originalPrice = (_ref11 = (_ref12 = (_ref13 = (_current$original_pri = current.original_price) !== null && _current$original_pri !== void 0 ? _current$original_pri : current.product_price) !== null && _ref13 !== void 0 ? _ref13 : current.price) !== null && _ref12 !== void 0 ? _ref12 : current.custom_price) !== null && _ref11 !== void 0 ? _ref11 : sourcePrice;
263
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, bundle), sourcePrice !== undefined ? {
264
+ price: sourcePrice
265
+ } : {}), originalPrice !== undefined ? {
266
+ original_price: originalPrice
267
+ } : {}), current.original_total !== undefined ? {
268
+ original_total: current.original_total
269
+ } : {});
270
+ });
271
+ };
121
272
  return {
122
273
  getProduct: function getProduct(product) {
123
- var _product$metadata, _product$metadata2, _product$metadata3, _product$metadata4, _product$metadata5, _product$metadata6;
274
+ var _product$metadata, _product$metadata2, _product$metadata3, _product$metadata4, _product$metadata5, _metadataAny$_promoti;
124
275
  // source_product_price 是权威源;兜底链:source → mainSelling − options(反推)→ 行 selling_price
125
276
  var metadataAny = product.metadata || {};
126
277
  var optionSum = sumOptionUnitPrice(product.product_option_item);
@@ -145,7 +296,7 @@ export function createDefaultOrderRulesHooks() {
145
296
  id: product.product_id,
146
297
  // Rules 引擎用 _id 作为 processedProductsMap 键;必须与购物车行级 identity 一致,
147
298
  // 否则同 SKU 不同小料会在 calcDiscount 重组时互相覆盖。
148
- // 不透明 identity 契约下,normalizeOrderProduct / restoreTempOrderFromStorage 已保证唯一值存在;
299
+ // 不透明 identity 契约下,normalizeOrderProduct / hydrate 已保证唯一值存在;
149
300
  // 留 fingerprint 分支仅作 Rules 单测里直接传裸 product 时的兜底。
150
301
  _id: (_product$metadata = product.metadata) !== null && _product$metadata !== void 0 && _product$metadata.unique_identification_number ? "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(product.metadata.unique_identification_number) : "".concat(product.product_id, "_").concat(product.product_variant_id, "_").concat(buildProductLineFingerprint(product.product_option_item, product.product_bundle)),
151
302
  // Rules 内部 getProductTotalPrice / getProductOriginTotalPrice 会各自再叠加 bundle + option,
@@ -161,16 +312,21 @@ export function createDefaultOrderRulesHooks() {
161
312
  bundle: product.product_bundle || [],
162
313
  booking_id: ((_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.booking_id) || null,
163
314
  isClient: false,
164
- isManualDiscount: ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.is_manual_discount) || false,
165
- holder_id: (_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.holder_id,
166
- startDate: ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.start_date) || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.startDate)
315
+ // 勿写死 false:否则 Rules 不会走 total≠origin_total 的手动价推断,
316
+ // 无券时会把 bundle 价还原成 original_price(手动改价套餐会从 20 回到 30)。
317
+ isManualDiscount: resolveRulesManualDiscountFlag(metadataAny),
318
+ holder_id: (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.holder_id,
319
+ startDate: ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.start_date) || ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.startDate),
320
+ main_product_selling_price: metadataAny.main_product_selling_price !== undefined ? new Decimal(Number(metadataAny.main_product_selling_price) || 0).minus(optionSum).toDecimalPlaces(2).toString() : undefined,
321
+ inPromotion: ((_metadataAny$_promoti = metadataAny._promotion) === null || _metadataAny$_promoti === void 0 ? void 0 : _metadataAny$_promoti.inPromotion) === true,
322
+ _promotion: metadataAny._promotion
167
323
  };
168
324
  },
169
325
  setProduct: function setProduct(product, values) {
170
- var _ref3, _values$quantity, _ref4, _metadataAny$source_p, _values$bundle, _values$discount_list, _values$quantity2;
171
- var nextNum = Number((_ref3 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref3 !== void 0 ? _ref3 : 1) || 1;
326
+ var _ref14, _values$quantity, _ref15, _metadataAny$source_p, _values$discount_list, _values$quantity2;
327
+ var nextNum = Number((_ref14 = (_values$quantity = values.quantity) !== null && _values$quantity !== void 0 ? _values$quantity : product.num) !== null && _ref14 !== void 0 ? _ref14 : 1) || 1;
172
328
  var metadataAny = product.metadata || {};
173
- var existedSource = (_ref4 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref4 !== void 0 ? _ref4 : '0';
329
+ var existedSource = (_ref15 = (_metadataAny$source_p = metadataAny.source_product_price) !== null && _metadataAny$source_p !== void 0 ? _metadataAny$source_p : product.selling_price) !== null && _ref15 !== void 0 ? _ref15 : '0';
174
330
  var nextOptions = product.product_option_item;
175
331
  var optionSum = sumOptionUnitPrice(nextOptions);
176
332
 
@@ -186,7 +342,7 @@ export function createDefaultOrderRulesHooks() {
186
342
  // 含 option 的 main_product_*
187
343
  var nextMainSellingPrice = new Decimal(Number(nextSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
188
344
  var nextMainOriginalPrice = new Decimal(Number(nextSourceOriginalPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
189
- var nextBundle = (_values$bundle = values.bundle) !== null && _values$bundle !== void 0 ? _values$bundle : product.product_bundle;
345
+ var nextBundle = values.bundle !== undefined ? mergeRulesBundlePrices(product.product_bundle, values.bundle) : product.product_bundle;
190
346
  var composedSellingPrice = composeLinePrice({
191
347
  mainPrice: nextMainSellingPrice,
192
348
  bundle: nextBundle
@@ -196,9 +352,14 @@ export function createDefaultOrderRulesHooks() {
196
352
  bundle: nextBundle,
197
353
  useOriginalBundle: true
198
354
  });
355
+ var finalOriginalPrice = resolveManualOverrideLineOriginalPrice({
356
+ num: nextNum,
357
+ metadata: metadataAny,
358
+ lineOriginalPrice: product.original_price
359
+ }, composedOriginalPrice);
199
360
  return _objectSpread(_objectSpread({}, product), {}, {
200
361
  selling_price: composedSellingPrice,
201
- original_price: composedOriginalPrice,
362
+ original_price: finalOriginalPrice,
202
363
  discount_list: (_values$discount_list = values.discount_list) !== null && _values$discount_list !== void 0 ? _values$discount_list : product.discount_list,
203
364
  num: (_values$quantity2 = values.quantity) !== null && _values$quantity2 !== void 0 ? _values$quantity2 : product.num,
204
365
  product_bundle: nextBundle,
@@ -337,11 +498,11 @@ function toMoneyString(value) {
337
498
  function formatSubmitBundleItems(bundle) {
338
499
  if (!Array.isArray(bundle)) return [];
339
500
  return bundle.map(function (b) {
340
- var _rawBundle$bundle_sel, _ref5, _rawBundle$price, _rawBundle$surcharge_, _rawBundle$num, _rawBundle$is_charge_, _rawBundle$bundle_var, _rawBundle$quantity, _rawBundle$extension_, _rawBundle$extension_2, _ref6, _rawBundle$price_type, _ref7, _rawBundle$price_type2, _rawBundle$bundle_gro, _rawBundle$bundle_id, _rawBundle$bundle_pro;
501
+ var _rawBundle$bundle_sel, _ref16, _rawBundle$price, _rawBundle$surcharge_, _rawBundle$num, _rawBundle$is_charge_, _rawBundle$bundle_var, _rawBundle$quantity, _rawBundle$extension_, _rawBundle$extension_2, _ref17, _rawBundle$price_type, _ref18, _rawBundle$price_type2, _rawBundle$bundle_gro, _rawBundle$bundle_id, _rawBundle$bundle_pro;
341
502
  var rawBundle = b && _typeof(b) === 'object' ? b : {};
342
503
  var existedMetadata = rawBundle.metadata && _typeof(rawBundle.metadata) === 'object' ? rawBundle.metadata : {};
343
504
  var sellingPrice = toMoneyString((_rawBundle$bundle_sel = rawBundle.bundle_selling_price) !== null && _rawBundle$bundle_sel !== void 0 ? _rawBundle$bundle_sel : rawBundle.price);
344
- var priceValue = (_ref5 = (_rawBundle$price = rawBundle.price) !== null && _rawBundle$price !== void 0 ? _rawBundle$price : rawBundle.custom_price) !== null && _ref5 !== void 0 ? _ref5 : rawBundle.bundle_selling_price;
505
+ var priceValue = (_ref16 = (_rawBundle$price = rawBundle.price) !== null && _rawBundle$price !== void 0 ? _rawBundle$price : rawBundle.custom_price) !== null && _ref16 !== void 0 ? _ref16 : rawBundle.bundle_selling_price;
345
506
  var relationSurchargeIds = Array.isArray(rawBundle.relation_surcharge_ids) ? rawBundle.relation_surcharge_ids : Array.isArray(existedMetadata.relation_surcharge_ids) ? existedMetadata.relation_surcharge_ids : [];
346
507
  var surchargeFee = toMoneyString((_rawBundle$surcharge_ = rawBundle.surcharge_fee) !== null && _rawBundle$surcharge_ !== void 0 ? _rawBundle$surcharge_ : existedMetadata.surcharge_fee);
347
508
  var productDiscountDifference = toBundleNumber(existedMetadata.product_discount_difference, 0);
@@ -354,8 +515,8 @@ function formatSubmitBundleItems(bundle) {
354
515
  extension_id: (_rawBundle$extension_ = rawBundle.extension_id) !== null && _rawBundle$extension_ !== void 0 ? _rawBundle$extension_ : 0,
355
516
  extension_type: (_rawBundle$extension_2 = rawBundle.extension_type) !== null && _rawBundle$extension_2 !== void 0 ? _rawBundle$extension_2 : 'normal',
356
517
  price: priceValue,
357
- price_type: (_ref6 = (_rawBundle$price_type = rawBundle.price_type) !== null && _rawBundle$price_type !== void 0 ? _rawBundle$price_type : rawBundle.custom_price_type) !== null && _ref6 !== void 0 ? _ref6 : '',
358
- price_type_ext: (_ref7 = (_rawBundle$price_type2 = rawBundle.price_type_ext) !== null && _rawBundle$price_type2 !== void 0 ? _rawBundle$price_type2 : rawBundle.custom_price_type_ext) !== null && _ref7 !== void 0 ? _ref7 : '',
518
+ price_type: (_ref17 = (_rawBundle$price_type = rawBundle.price_type) !== null && _rawBundle$price_type !== void 0 ? _rawBundle$price_type : rawBundle.custom_price_type) !== null && _ref17 !== void 0 ? _ref17 : '',
519
+ price_type_ext: (_ref18 = (_rawBundle$price_type2 = rawBundle.price_type_ext) !== null && _rawBundle$price_type2 !== void 0 ? _rawBundle$price_type2 : rawBundle.custom_price_type_ext) !== null && _ref18 !== void 0 ? _ref18 : '',
359
520
  bundle_selling_price: sellingPrice,
360
521
  option: formatSubmitOptionItems(rawBundle.option),
361
522
  bundle_group_id: (_rawBundle$bundle_gro = rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.bundle_group_id) !== null && _rawBundle$bundle_gro !== void 0 ? _rawBundle$bundle_gro : rawBundle === null || rawBundle === void 0 ? void 0 : rawBundle.group_id,
@@ -388,12 +549,17 @@ function formatSubmitBundleItems(bundle) {
388
549
  */
389
550
  function normalizeSubmitProduct(product) {
390
551
  var _rawMetadata$product_, _submitProduct$produc;
391
- var _ref8 = product,
392
- _runtimeUid = _ref8.unique_identification_number,
393
- submitProduct = _objectWithoutProperties(_ref8, _excluded);
552
+ var _ref19 = product,
553
+ _runtimeUid = _ref19.unique_identification_number,
554
+ submitProduct = _objectWithoutProperties(_ref19, _excluded);
394
555
  var num = submitProduct.num,
395
556
  productOptionItem = submitProduct.product_option_item,
396
557
  _productSurchargeFee = submitProduct.surcharge_fee,
558
+ _deprecatedDiscountAmount = submitProduct.discount_amount,
559
+ _deprecatedDiscountType = submitProduct.discount_type,
560
+ _deprecatedDiscountway = submitProduct.discountway,
561
+ _deprecatedProductDiscountReason = submitProduct.product_discount_reason,
562
+ _deprecatedDiscountPer = submitProduct.discount_per,
397
563
  productRest = _objectWithoutProperties(submitProduct, _excluded2);
398
564
  var rawMetadata = submitProduct.metadata || {};
399
565
  var bookingUid = rawMetadata.booking_uid;
@@ -423,7 +589,7 @@ function normalizeSubmitProduct(product) {
423
589
  } : {}), {}, {
424
590
  product_quantity: toBundleNumber(num !== null && num !== void 0 ? num : submitProduct.product_quantity, 1),
425
591
  product_sku: productSku,
426
- discount_list: submitProduct.discount_list || [],
592
+ discount_list: normalizeOrderProductDiscountList(submitProduct.discount_list),
427
593
  product_bundle: formatSubmitBundleItems(submitProduct.product_bundle),
428
594
  metadata: cleanMetadata,
429
595
  // 出站兼容:后端消费 payment_price 字段,这里从 selling_price 直接派生。
@@ -502,22 +668,23 @@ export function createDefaultTempOrder(params) {
502
668
  return {
503
669
  order_id: null,
504
670
  external_sale_number: '',
505
- order_number: '',
506
- shop_order_number: '',
507
- shop_full_order_number: '',
508
- type: 'appointment_booking',
509
- business_code: 'appointment_booking',
671
+ order_number: null,
672
+ shop_order_number: null,
673
+ shop_full_order_number: null,
674
+ type: '',
675
+ business_code: undefined,
510
676
  platform: 'h5',
511
677
  sales_channel: 'my_pisel',
512
678
  order_sales_channel: 'online_store',
513
679
  status: 'normal',
514
680
  payment_status: 'payment_processing',
515
681
  shipping_status: 'unfulfilled',
516
- customer_id: null,
682
+ customer_id: 0,
517
683
  customer_name: '',
518
684
  country_calling_code: '',
519
685
  phone: '',
520
686
  email: '',
687
+ customer: null,
521
688
  is_price_include_tax: 1,
522
689
  tax_title: '',
523
690
  tax_country_code: '',
@@ -537,7 +704,6 @@ export function createDefaultTempOrder(params) {
537
704
  bookings: [],
538
705
  payments: [],
539
706
  surcharges: [],
540
- discount_list: [],
541
707
  relation_forms: [],
542
708
  contacts: [],
543
709
  contacts_info: null,
@@ -549,7 +715,7 @@ export function createDefaultTempOrder(params) {
549
715
  };
550
716
  }
551
717
  export function buildSubmitPayload(params) {
552
- var _ref10, _ref11, _ref12, _tempOrder$is_price_i, _tempOrder$is_deposit;
718
+ var _tempOrder$customer_i, _ref21, _tempOrder$is_price_i, _tempOrder$is_deposit;
553
719
  var tempOrder = params.tempOrder,
554
720
  cacheId = params.cacheId,
555
721
  _params$now = params.now,
@@ -561,33 +727,48 @@ export function buildSubmitPayload(params) {
561
727
  enhance = params.enhance;
562
728
  var scheduleDate = tempOrder.schedule_date || tempOrder.created_at || formatDateTime(now);
563
729
  var bookingUuid = createUuidV4();
564
- var _ref9 = tempOrder,
565
- _extend = _ref9._extend,
566
- _relationId = _ref9.relation_id,
567
- _tableFormId = _ref9.table_form_id,
568
- _resourceId = _ref9.resource_id,
569
- _summary = _ref9.summary,
570
- _lastOrderInfo = _ref9.lastOrderInfo,
571
- _paidAmount = _ref9.paid_amount,
572
- _shopId = _ref9.shop_id,
573
- _shopNote = _ref9.shop_note,
574
- _shopServiceType = _ref9.shop_service_type,
575
- _startTime = _ref9.start_time,
576
- _customer = _ref9.customer,
577
- _shopFullOrderNumber = _ref9.shop_full_order_number,
578
- _rootTaxFee = _ref9.tax_fee,
579
- _totalAmount = _ref9.total_amount,
580
- _totalRefundAmount = _ref9.total_refund_amount,
581
- _createDate = _ref9.create_date,
582
- _holderId = _ref9.holder_id,
583
- tempOrderRest = _objectWithoutProperties(_ref9, _excluded3);
730
+ var _ref20 = tempOrder,
731
+ _extend = _ref20._extend,
732
+ _relationId = _ref20.relation_id,
733
+ _tableFormId = _ref20.table_form_id,
734
+ _resourceId = _ref20.resource_id,
735
+ _summary = _ref20.summary,
736
+ _lastOrderInfo = _ref20.lastOrderInfo,
737
+ _paidAmount = _ref20.paid_amount,
738
+ _shopId = _ref20.shop_id,
739
+ _shopNote = _ref20.shop_note,
740
+ _shopServiceType = _ref20.shop_service_type,
741
+ _startTime = _ref20.start_time,
742
+ _customer = _ref20.customer,
743
+ _discountList = _ref20.discount_list,
744
+ _rootTaxFee = _ref20.tax_fee,
745
+ _totalAmount = _ref20.total_amount,
746
+ _totalRefundAmount = _ref20.total_refund_amount,
747
+ _createDate = _ref20.create_date,
748
+ _holderId = _ref20.holder_id,
749
+ tempOrderRest = _objectWithoutProperties(_ref20, _excluded3);
750
+ var submitType = type !== null && type !== void 0 ? type : tempOrder.type;
751
+ if (!submitType) {
752
+ var _tempOrder$bookings;
753
+ // 如果外部没有传递 types,根据订单里当前是否有 bookings 来决定是 appointment_booking 还是 virtual
754
+ if (tempOrder !== null && tempOrder !== void 0 && (_tempOrder$bookings = tempOrder.bookings) !== null && _tempOrder$bookings !== void 0 && _tempOrder$bookings.length) {
755
+ submitType = 'appointment_booking';
756
+ } else {
757
+ submitType = 'virtual';
758
+ }
759
+ }
584
760
  var payload = _objectSpread(_objectSpread({}, tempOrderRest), {}, {
761
+ customer_id: (_tempOrder$customer_i = tempOrder.customer_id) !== null && _tempOrder$customer_i !== void 0 ? _tempOrder$customer_i : 1,
762
+ customer_name: tempOrder.customer_name || 'Select a customer',
763
+ order_number: null,
764
+ shop_order_number: null,
765
+ shop_full_order_number: null,
585
766
  platform: normalizeSubmitPlatform(platform),
586
767
  request_unique_idempotency_token: tempOrder.request_unique_idempotency_token || "".concat(tempOrder.external_sale_number, "_").concat(now.getTime()),
587
- type: (_ref10 = type !== null && type !== void 0 ? type : tempOrder.type) !== null && _ref10 !== void 0 ? _ref10 : 'table-order',
588
- business_code: (_ref11 = businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code) !== null && _ref11 !== void 0 ? _ref11 : 'table-order',
768
+ type: submitType,
769
+ business_code: businessCode !== null && businessCode !== void 0 ? businessCode : tempOrder.business_code,
589
770
  sales_channel: tempOrder.sales_channel || 'my_pisel',
590
- order_sales_channel: (_ref12 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref12 !== void 0 ? _ref12 : 'online_store',
771
+ order_sales_channel: (_ref21 = channel !== null && channel !== void 0 ? channel : tempOrder.order_sales_channel) !== null && _ref21 !== void 0 ? _ref21 : 'online_store',
591
772
  status: tempOrder.status || 'normal',
592
773
  payment_status: tempOrder.payment_status || 'payment_processing',
593
774
  // shipping_status: tempOrder.shipping_status || 'unfulfilled',
@@ -600,25 +781,23 @@ export function buildSubmitPayload(params) {
600
781
  note: tempOrder.note || '',
601
782
  delivery_type: tempOrder.delivery_type || 'nil',
602
783
  schedule_date: scheduleDate,
603
- created_at: tempOrder.created_at || formatDateTime(now),
784
+ // created_at: tempOrder.created_at || formatDateTime(now), 和后端协定这个字段先不提交到接口
604
785
  bookings: (tempOrder.bookings || []).filter(function (booking) {
605
- var _parent_id;
606
- return Number((_parent_id = booking.parent_id) !== null && _parent_id !== void 0 ? _parent_id : 0) !== 0;
786
+ return Number(booking.parent_id) !== 0;
607
787
  }).map(function (booking) {
608
788
  return normalizeSubmitBooking(booking);
609
789
  }),
610
790
  payments: tempOrder.payments || [],
611
- // discount_list: tempOrder.discount_list || [],
612
791
  relation_forms: tempOrder.relation_forms || [],
613
792
  // contacts: tempOrder.contacts || [],
614
793
  contacts_info: tempOrder.contacts_info && !Array.isArray(tempOrder.contacts_info) ? tempOrder.contacts_info : null,
615
794
  // holder: tempOrder.holder || null,
616
795
  // summary,
617
796
  metadata: function () {
618
- var _ref13 = tempOrder.metadata || {},
619
- _collectPax = _ref13.collect_pax,
620
- _tableOccupancyDuration = _ref13.table_occupancy_duration,
621
- rest = _objectWithoutProperties(_ref13, _excluded4);
797
+ var _ref22 = tempOrder.metadata || {},
798
+ _collectPax = _ref22.collect_pax,
799
+ _tableOccupancyDuration = _ref22.table_occupancy_duration,
800
+ rest = _objectWithoutProperties(_ref22, _excluded4);
622
801
  return _objectSpread({}, rest);
623
802
  }(),
624
803
  products: (tempOrder.products || []).map(function (product) {
@@ -713,4 +892,169 @@ export function formatV1Product(products) {
713
892
  };
714
893
  });
715
894
  }
716
- export { createEmptySummary } from "../../solution/ScanOrder/utils";
895
+
896
+ /**
897
+ * 判断 holder_id 是否已分配(非空)。
898
+ *
899
+ * @example
900
+ * hasAssignedHolderId(12); // true
901
+ * hasAssignedHolderId([]); // false
902
+ */
903
+ export function hasAssignedHolderId(value) {
904
+ if (value === undefined || value === null || value === '') return false;
905
+ if (Array.isArray(value)) return value.length > 0;
906
+ return true;
907
+ }
908
+
909
+ /**
910
+ * 清空 tempOrder 购物车行上的 holder 分配(products / bookings / runtime origin)。
911
+ * 移除或更换下单客户时调用,与 booking 页换客户清 holder 行为对齐。
912
+ *
913
+ * @example
914
+ * clearTempOrderHolderAssignments(tempOrder);
915
+ */
916
+ export function clearTempOrderHolderAssignments(tempOrder) {
917
+ var _tempOrder$_extend;
918
+ var changed = false;
919
+ var resetHolderField = function resetHolderField(target) {
920
+ var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'holder_id';
921
+ if (!hasAssignedHolderId(target[key])) return;
922
+ target[key] = null;
923
+ changed = true;
924
+ };
925
+ var _iterator4 = _createForOfIteratorHelper(tempOrder.products || []),
926
+ _step4;
927
+ try {
928
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
929
+ var product = _step4.value;
930
+ if (product.metadata && _typeof(product.metadata) === 'object') {
931
+ resetHolderField(product.metadata);
932
+ }
933
+ }
934
+ } catch (err) {
935
+ _iterator4.e(err);
936
+ } finally {
937
+ _iterator4.f();
938
+ }
939
+ var _iterator5 = _createForOfIteratorHelper(tempOrder.bookings || []),
940
+ _step5;
941
+ try {
942
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
943
+ var booking = _step5.value;
944
+ var bookingRecord = booking;
945
+ if (booking.metadata && _typeof(booking.metadata) === 'object') {
946
+ resetHolderField(booking.metadata);
947
+ }
948
+ if (bookingRecord.holder !== undefined && bookingRecord.holder !== null) {
949
+ delete bookingRecord.holder;
950
+ changed = true;
951
+ }
952
+ }
953
+ } catch (err) {
954
+ _iterator5.e(err);
955
+ } finally {
956
+ _iterator5.f();
957
+ }
958
+ var productsByUid = (_tempOrder$_extend = tempOrder._extend) === null || _tempOrder$_extend === void 0 ? void 0 : _tempOrder$_extend.productsByUid;
959
+ if (productsByUid && _typeof(productsByUid) === 'object') {
960
+ for (var _i4 = 0, _Object$values = Object.values(productsByUid); _i4 < _Object$values.length; _i4++) {
961
+ var entry = _Object$values[_i4];
962
+ var origin = entry === null || entry === void 0 ? void 0 : entry.origin;
963
+ if (!origin || _typeof(origin) !== 'object') continue;
964
+ if (origin.metadata && _typeof(origin.metadata) === 'object') {
965
+ resetHolderField(origin.metadata);
966
+ }
967
+ if (origin._extend && _typeof(origin._extend) === 'object') {
968
+ resetHolderField(origin._extend);
969
+ }
970
+ }
971
+ }
972
+ return changed;
973
+ }
974
+
975
+ /**
976
+ * 读取购物车行的 stable uid(优先 metadata.unique_identification_number)。
977
+ *
978
+ * @example
979
+ * getOrderProductLineUid({ metadata: { unique_identification_number: 'line-1' } }); // 'line-1'
980
+ */
981
+ export function getOrderProductLineUid(product) {
982
+ var _product$metadata$uni, _product$metadata6;
983
+ if (!product || _typeof(product) !== 'object') return null;
984
+ var uid = (_product$metadata$uni = (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.unique_identification_number) !== null && _product$metadata$uni !== void 0 ? _product$metadata$uni : product.unique_identification_number;
985
+ if (uid === undefined || uid === null || uid === '') return null;
986
+ return String(uid);
987
+ }
988
+
989
+ /**
990
+ * 判断展示字段是否为空(含 i18n 对象全空)。
991
+ *
992
+ * @example
993
+ * isEmptyOrderProductDisplayValue(''); // true
994
+ * isEmptyOrderProductDisplayValue({ auto: '桌台费' }); // false
995
+ */
996
+ export function isEmptyOrderProductDisplayValue(value) {
997
+ if (value === undefined || value === null) return true;
998
+ if (typeof value === 'string') return value.trim() === '';
999
+ if (_typeof(value) === 'object') {
1000
+ var record = value;
1001
+ return !Object.values(record).some(function (item) {
1002
+ return typeof item === 'string' && item.trim() !== '';
1003
+ });
1004
+ }
1005
+ return false;
1006
+ }
1007
+
1008
+ /**
1009
+ * calcDiscount / applyDiscount 回写时 Rules 往往不带 product_title 等展示字段;
1010
+ * 用旧行补齐,避免编辑态 hydrate 后标题被冲掉。
1011
+ *
1012
+ * @example
1013
+ * mergeOrderProductDisplayFields(
1014
+ * { product_title: { auto: '桌台费' }, metadata: { unique_identification_number: 'u1' } },
1015
+ * { selling_price: '10.00', metadata: { unique_identification_number: 'u1' } },
1016
+ * );
1017
+ */
1018
+ export function mergeOrderProductDisplayFields(previous, next) {
1019
+ var merged = _objectSpread({}, next);
1020
+ var displayFields = ['product_title', 'product_name', 'product_cover', 'cover', 'variant_title', 'product_sku'];
1021
+ displayFields.forEach(function (field) {
1022
+ if (isEmptyOrderProductDisplayValue(merged[field]) && !isEmptyOrderProductDisplayValue(previous[field])) {
1023
+ merged[field] = previous[field];
1024
+ }
1025
+ });
1026
+ if (previous.metadata || next.metadata) {
1027
+ merged.metadata = _objectSpread(_objectSpread({}, previous.metadata || {}), next.metadata || {});
1028
+ ['product_title', 'product_name'].forEach(function (field) {
1029
+ var _previous$metadata;
1030
+ if (isEmptyOrderProductDisplayValue(merged.metadata[field]) && !isEmptyOrderProductDisplayValue((_previous$metadata = previous.metadata) === null || _previous$metadata === void 0 ? void 0 : _previous$metadata[field])) {
1031
+ merged.metadata[field] = previous.metadata[field];
1032
+ }
1033
+ });
1034
+ }
1035
+ if (previous._extend && !merged._extend) {
1036
+ merged._extend = previous._extend;
1037
+ }
1038
+ return merged;
1039
+ }
1040
+
1041
+ /**
1042
+ * 按 uid 索引 tempOrder.products,供 applyDiscount 合并展示字段。
1043
+ *
1044
+ * @example
1045
+ * indexOrderProductsByUid([{ metadata: { unique_identification_number: 'u1' } }]);
1046
+ */
1047
+ export function indexOrderProductsByUid(products) {
1048
+ var map = new Map();
1049
+ (products || []).forEach(function (product, index) {
1050
+ var uid = getOrderProductLineUid(product);
1051
+ if (uid) {
1052
+ map.set(uid, product);
1053
+ return;
1054
+ }
1055
+ map.set("__index__:".concat(index), product);
1056
+ });
1057
+ return map;
1058
+ }
1059
+ export { createEmptySummary } from "../../solution/ScanOrder/utils";
1060
+ export { buildManualProductDiscountItem, ensureManualProductDiscountList, findManualProductDiscountItem, mergeManualProductDiscountIntoList, resolveManualDiscountMessage, resolveManualDiscountOriginTotal, resolveManualDiscountReasonFromSources, resolveSafeProductNum, shouldBuildManualProductDiscount, syncManualProductDiscountProductNum, stripManualProductDiscountItems } from "./utils/manualProductDiscount";
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -47,7 +47,6 @@ export declare class QuotationModule extends BaseModule implements Module {
47
47
  customer_id?: number | string;
48
48
  }): Map<string, string | null>;
49
49
  setScheduleResolver(resolver: (id: number) => ScheduleItem | undefined): void;
50
- private filterQuotationsByCustomer;
51
50
  private isQuotationVisibleForCustomer;
52
51
  private hasValidCustomerId;
53
52
  private isQuotationActiveAt;