@pisell/pisellos 2.2.323 → 2.2.325

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 (199) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/inventory/index.d.ts +92 -0
  4. package/dist/inventory/index.js +509 -0
  5. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  6. package/dist/modules/BookingContext/index.d.ts +2 -2
  7. package/dist/modules/BookingContext/index.js +55 -25
  8. package/dist/modules/BookingContext/types.d.ts +2 -0
  9. package/dist/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  10. package/dist/modules/BookingContext/utils/calendarBooking.js +207 -0
  11. package/dist/modules/BookingContext/utils/index.d.ts +1 -0
  12. package/dist/modules/BookingContext/utils/index.js +1 -0
  13. package/dist/modules/BookingContext/utils/productExtend.d.ts +20 -1
  14. package/dist/modules/BookingContext/utils/productExtend.js +122 -29
  15. package/dist/modules/Date/index.d.ts +1 -1
  16. package/dist/modules/Date/index.js +60 -14
  17. package/dist/modules/Date/types.d.ts +5 -0
  18. package/dist/modules/Discount/index.js +1 -0
  19. package/dist/modules/OpenData/index.d.ts +1 -0
  20. package/dist/modules/OpenData/index.js +1 -0
  21. package/dist/modules/OpenData/salesSettings.d.ts +32 -0
  22. package/dist/modules/OpenData/salesSettings.js +80 -0
  23. package/dist/modules/OpenData/types.d.ts +16 -0
  24. package/dist/modules/OpenData/utils.d.ts +1 -1
  25. package/dist/modules/OpenData/utils.js +3 -2
  26. package/dist/modules/Order/index.d.ts +55 -12
  27. package/dist/modules/Order/index.js +2699 -1411
  28. package/dist/modules/Order/types.d.ts +43 -5
  29. package/dist/modules/Order/types.js +4 -0
  30. package/dist/modules/Order/unpaidAmountGap.d.ts +6 -0
  31. package/dist/modules/Order/unpaidAmountGap.js +72 -0
  32. package/dist/modules/Order/utils/discountProductLineIdentity.js +2 -2
  33. package/dist/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  34. package/dist/modules/Order/utils/productVoucherGroups.js +115 -0
  35. package/dist/modules/Order/utils.d.ts +3 -1
  36. package/dist/modules/Order/utils.js +6 -2
  37. package/dist/modules/Product/index.d.ts +1 -1
  38. package/dist/modules/ProductList/clientDataVariants.js +6 -2
  39. package/dist/modules/ProductList/index.d.ts +2 -0
  40. package/dist/modules/ProductList/index.js +161 -51
  41. package/dist/modules/ResourcePlanner/planner.js +58 -2
  42. package/dist/modules/ResourcePlanner/types.d.ts +13 -0
  43. package/dist/modules/Rules/index.d.ts +2 -0
  44. package/dist/modules/Rules/index.js +58 -39
  45. package/dist/modules/Schedule/index.d.ts +7 -1
  46. package/dist/modules/Schedule/index.js +155 -39
  47. package/dist/modules/Schedule/types.d.ts +2 -0
  48. package/dist/modules/bookingReadValidation.d.ts +6 -0
  49. package/dist/modules/bookingReadValidation.js +72 -0
  50. package/dist/plugins/request.d.ts +2 -0
  51. package/dist/server/index.d.ts +8 -0
  52. package/dist/server/index.js +1458 -1166
  53. package/dist/server/modules/order/index.js +2 -1
  54. package/dist/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  55. package/dist/shared/receipt/customerInvoiceLanguages.js +5 -3
  56. package/dist/shared/receipt/small-ticket.d.ts +4 -0
  57. package/dist/shared/receipt/small-ticket.js +70 -12
  58. package/dist/solution/BaseSales/index.d.ts +39 -5
  59. package/dist/solution/BaseSales/index.js +1828 -1462
  60. package/dist/solution/BaseSales/types.d.ts +1 -0
  61. package/dist/solution/BaseSales/types.js +1 -0
  62. package/dist/solution/BookingByStep/index.d.ts +16 -2
  63. package/dist/solution/BookingByStep/index.js +676 -361
  64. package/dist/solution/BookingByStep/utils/resources.d.ts +10 -0
  65. package/dist/solution/BookingByStep/utils/resources.js +117 -76
  66. package/dist/solution/BookingTicket/index.d.ts +15 -3
  67. package/dist/solution/BookingTicket/index.js +249 -135
  68. package/dist/solution/BookingTicket/types.d.ts +14 -2
  69. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
  70. package/dist/solution/BookingTicket/utils/addProductDecision.js +39 -11
  71. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  72. package/dist/solution/BookingTicket/utils/resolveUniqueCartDetail.js +188 -0
  73. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
  74. package/dist/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +88 -0
  75. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  76. package/dist/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  77. package/dist/solution/OrderInvoicePreview/index.js +14 -8
  78. package/dist/solution/ScanOrder/index.d.ts +2 -0
  79. package/dist/solution/ScanOrder/index.js +166 -67
  80. package/dist/solution/ScanOrder/menuAvailability.d.ts +24 -0
  81. package/dist/solution/ScanOrder/menuAvailability.js +363 -0
  82. package/dist/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
  83. package/dist/solution/UnifiedBookingSales/catalogQueryBatch.js +202 -0
  84. package/dist/solution/UnifiedBookingSales/index.d.ts +96 -4
  85. package/dist/solution/UnifiedBookingSales/index.js +3374 -1177
  86. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  87. package/dist/solution/UnifiedBookingSales/remoteOccupancyCache.js +4 -0
  88. package/dist/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  89. package/dist/solution/UnifiedBookingSales/salesSettings.js +81 -0
  90. package/dist/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  91. package/dist/solution/UnifiedBookingSales/sessionResourceCache.js +271 -0
  92. package/dist/solution/UnifiedBookingSales/types.d.ts +71 -2
  93. package/dist/solution/UnifiedBookingSales/types.js +7 -1
  94. package/dist/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  95. package/dist/solution/UnifiedBookingSales/venueCatalogSession.js +283 -0
  96. package/dist/utils/platform.d.ts +2 -0
  97. package/dist/utils/platform.js +6 -0
  98. package/dist/utils/pos-receipt-auto-print.d.ts +4 -0
  99. package/dist/utils/pos-receipt-auto-print.js +14 -0
  100. package/lib/index.d.ts +1 -0
  101. package/lib/index.js +12 -0
  102. package/lib/inventory/index.d.ts +92 -0
  103. package/lib/inventory/index.js +287 -0
  104. package/lib/model/strategy/adapter/promotion/index.js +46 -1
  105. package/lib/modules/BookingContext/index.d.ts +2 -2
  106. package/lib/modules/BookingContext/index.js +42 -10
  107. package/lib/modules/BookingContext/types.d.ts +2 -0
  108. package/lib/modules/BookingContext/utils/calendarBooking.d.ts +15 -0
  109. package/lib/modules/BookingContext/utils/calendarBooking.js +156 -0
  110. package/lib/modules/BookingContext/utils/index.d.ts +1 -0
  111. package/lib/modules/BookingContext/utils/index.js +11 -0
  112. package/lib/modules/BookingContext/utils/productExtend.d.ts +20 -1
  113. package/lib/modules/BookingContext/utils/productExtend.js +96 -7
  114. package/lib/modules/Date/index.d.ts +1 -1
  115. package/lib/modules/Date/index.js +28 -5
  116. package/lib/modules/Date/types.d.ts +5 -0
  117. package/lib/modules/Discount/index.js +1 -0
  118. package/lib/modules/OpenData/index.d.ts +1 -0
  119. package/lib/modules/OpenData/index.js +12 -0
  120. package/lib/modules/OpenData/salesSettings.d.ts +32 -0
  121. package/lib/modules/OpenData/salesSettings.js +70 -0
  122. package/lib/modules/OpenData/types.d.ts +16 -0
  123. package/lib/modules/OpenData/utils.d.ts +1 -1
  124. package/lib/modules/OpenData/utils.js +3 -2
  125. package/lib/modules/Order/index.d.ts +55 -12
  126. package/lib/modules/Order/index.js +659 -80
  127. package/lib/modules/Order/types.d.ts +43 -5
  128. package/lib/modules/Order/types.js +2 -0
  129. package/lib/modules/Order/unpaidAmountGap.d.ts +6 -0
  130. package/lib/modules/Order/unpaidAmountGap.js +60 -0
  131. package/lib/modules/Order/utils/discountProductLineIdentity.js +1 -1
  132. package/lib/modules/Order/utils/productVoucherGroups.d.ts +15 -0
  133. package/lib/modules/Order/utils/productVoucherGroups.js +64 -0
  134. package/lib/modules/Order/utils.d.ts +3 -1
  135. package/lib/modules/Order/utils.js +6 -2
  136. package/lib/modules/Product/index.d.ts +1 -1
  137. package/lib/modules/ProductList/clientDataVariants.js +6 -2
  138. package/lib/modules/ProductList/index.d.ts +2 -0
  139. package/lib/modules/ProductList/index.js +74 -0
  140. package/lib/modules/ResourcePlanner/planner.js +52 -1
  141. package/lib/modules/ResourcePlanner/types.d.ts +13 -0
  142. package/lib/modules/Rules/index.d.ts +2 -0
  143. package/lib/modules/Rules/index.js +25 -9
  144. package/lib/modules/Schedule/index.d.ts +7 -1
  145. package/lib/modules/Schedule/index.js +68 -4
  146. package/lib/modules/Schedule/types.d.ts +2 -0
  147. package/lib/modules/bookingReadValidation.d.ts +6 -0
  148. package/lib/modules/bookingReadValidation.js +56 -0
  149. package/lib/plugins/request.d.ts +2 -0
  150. package/lib/server/index.d.ts +8 -0
  151. package/lib/server/index.js +194 -19
  152. package/lib/server/modules/order/index.js +2 -1
  153. package/lib/shared/receipt/customerInvoiceLanguages.d.ts +1 -1
  154. package/lib/shared/receipt/customerInvoiceLanguages.js +5 -3
  155. package/lib/shared/receipt/small-ticket.d.ts +4 -0
  156. package/lib/shared/receipt/small-ticket.js +63 -8
  157. package/lib/solution/BaseSales/index.d.ts +39 -5
  158. package/lib/solution/BaseSales/index.js +212 -18
  159. package/lib/solution/BaseSales/types.d.ts +1 -0
  160. package/lib/solution/BaseSales/types.js +1 -0
  161. package/lib/solution/BookingByStep/index.d.ts +16 -2
  162. package/lib/solution/BookingByStep/index.js +222 -14
  163. package/lib/solution/BookingByStep/utils/resources.d.ts +10 -0
  164. package/lib/solution/BookingByStep/utils/resources.js +25 -15
  165. package/lib/solution/BookingTicket/index.d.ts +15 -3
  166. package/lib/solution/BookingTicket/index.js +47 -4
  167. package/lib/solution/BookingTicket/types.d.ts +14 -2
  168. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +3 -1
  169. package/lib/solution/BookingTicket/utils/addProductDecision.js +37 -6
  170. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.d.ts +8 -0
  171. package/lib/solution/BookingTicket/utils/resolveUniqueCartDetail.js +136 -0
  172. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.d.ts +8 -0
  173. package/lib/solution/BookingTicket/utils/scan/applyProductVoucherCollectionScan.js +54 -0
  174. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +1 -0
  175. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -1
  176. package/lib/solution/OrderInvoicePreview/index.js +7 -1
  177. package/lib/solution/ScanOrder/index.d.ts +2 -0
  178. package/lib/solution/ScanOrder/index.js +72 -2
  179. package/lib/solution/ScanOrder/menuAvailability.d.ts +24 -0
  180. package/lib/solution/ScanOrder/menuAvailability.js +203 -0
  181. package/lib/solution/UnifiedBookingSales/catalogQueryBatch.d.ts +21 -0
  182. package/lib/solution/UnifiedBookingSales/catalogQueryBatch.js +109 -0
  183. package/lib/solution/UnifiedBookingSales/index.d.ts +96 -4
  184. package/lib/solution/UnifiedBookingSales/index.js +1316 -73
  185. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.d.ts +2 -0
  186. package/lib/solution/UnifiedBookingSales/remoteOccupancyCache.js +2 -0
  187. package/lib/solution/UnifiedBookingSales/salesSettings.d.ts +16 -0
  188. package/lib/solution/UnifiedBookingSales/salesSettings.js +72 -0
  189. package/lib/solution/UnifiedBookingSales/sessionResourceCache.d.ts +27 -0
  190. package/lib/solution/UnifiedBookingSales/sessionResourceCache.js +199 -0
  191. package/lib/solution/UnifiedBookingSales/types.d.ts +71 -2
  192. package/lib/solution/UnifiedBookingSales/types.js +4 -1
  193. package/lib/solution/UnifiedBookingSales/venueCatalogSession.d.ts +32 -0
  194. package/lib/solution/UnifiedBookingSales/venueCatalogSession.js +155 -0
  195. package/lib/utils/platform.d.ts +2 -0
  196. package/lib/utils/platform.js +7 -0
  197. package/lib/utils/pos-receipt-auto-print.d.ts +4 -0
  198. package/lib/utils/pos-receipt-auto-print.js +13 -0
  199. package/package.json +1 -1
@@ -5,7 +5,7 @@ import type { OrderProduct, OrderProductIdentity, AddProductBookingInput } from
5
5
  * cart.addProduct 两阶段决策(与 ticketBooking `handleSelectProduct` 对齐):
6
6
  *
7
7
  * 1. `requiresDetail`:规格 / SKU / 套餐 / Session / 称重弹窗(门禁:`isOpenDetailModal` / `cartDetailValue` / `open_sold_weight`)
8
- * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(kiosk 强制进入;其他渠道由 `getIsAutoClose` 决定)
8
+ * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(自助终端强制进入;其他渠道由 `getIsAutoClose` 决定)
9
9
  * 3. `add`:两关均通过,直接 transform + 加车
10
10
  */
11
11
  export type AddProductDecision = {
@@ -41,6 +41,8 @@ export declare function decideAfterDetail(cacheItem: any, ctx?: AddProductDecide
41
41
  * @deprecated 请用 `decideAddProduct`;保留兼容:autoClose=true 仅表示可直接加车(action=add)。
42
42
  */
43
43
  export interface AddProductRequiresDetailPayload {
44
+ /** Same prepared decision cache supplied to the Host; never a separate Flow preflight. */
45
+ preparedCacheItem?: any;
44
46
  item: ProductData | Record<string, any>;
45
47
  /** UI 需展示的子弹窗开关。 */
46
48
  showConfig: {
@@ -15,14 +15,16 @@ exports.prepareBookingCacheItem = prepareBookingCacheItem;
15
15
  exports.transformDetailToProductAndBooking = transformDetailToProductAndBooking;
16
16
  var _dayjs = _interopRequireDefault(require("dayjs"));
17
17
  var _BookingContext = require("../../../modules/BookingContext");
18
+ var _resolveUniqueCartDetail = require("./resolveUniqueCartDetail");
18
19
  var _transformBaseProductToOrderProduct = require("../../BaseSales/utils/transformBaseProductToOrderProduct");
19
20
  var _weighingProductSku = require("./weighingProductSku");
21
+ var _platform = require("../../../utils/platform");
20
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
23
  /**
22
24
  * cart.addProduct 两阶段决策(与 ticketBooking `handleSelectProduct` 对齐):
23
25
  *
24
26
  * 1. `requiresDetail`:规格 / SKU / 套餐 / Session / 称重弹窗(门禁:`isOpenDetailModal` / `cartDetailValue` / `open_sold_weight`)
25
- * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(kiosk 强制进入;其他渠道由 `getIsAutoClose` 决定)
27
+ * 2. `requiresBookingEdit`:资源 / 时间编辑抽屉(自助终端强制进入;其他渠道由 `getIsAutoClose` 决定)
26
28
  * 3. `add`:两关均通过,直接 transform + 加车
27
29
  */
28
30
 
@@ -39,11 +41,12 @@ function needsSpecDetailModal(item) {
39
41
  }
40
42
 
41
43
  /**
42
- * 第二段:预约商品是否仍需打开资源 / 时间编辑(kiosk 强制打开,其他渠道与 info2 `cacheItem.autoClose` 等价)。
44
+ * 第二段:预约商品是否仍需打开资源 / 时间编辑(自助终端强制打开,其他渠道与 info2 `cacheItem.autoClose` 等价)。
43
45
  */
44
46
  function needsBookingEdit(cacheItem, ctx) {
47
+ if ((0, _BookingContext.getCalendarBookingRange)(cacheItem, ctx)) return (0, _BookingContext.calendarBookingNeedsInput)(cacheItem);
45
48
  if (isNormalBookingProduct(cacheItem)) return false;
46
- if (ctx?.channel === 'kiosk') return true;
49
+ if ((0, _platform.isSelfServicePlatform)(ctx?.channel)) return true;
47
50
  const isAutoAllocationOn = ctx?.isAutoAllocationOn || (() => true);
48
51
  return !(0, _BookingContext.getIsAutoClose)(cacheItem, isAutoAllocationOn);
49
52
  }
@@ -60,13 +63,26 @@ function buildRequiresBookingEditPayload(cacheItem, ctx) {
60
63
  */
61
64
  function decideAddProduct(item, ctx) {
62
65
  const derivedCtx = withDerivedBookingCtx(ctx);
63
- if (needsSpecDetailModal(item)) {
66
+ const calendarRange = (0, _BookingContext.getCalendarBookingRange)(item, derivedCtx);
67
+ const uniqueValue = calendarRange ? (0, _resolveUniqueCartDetail.resolveUniqueCartDetailValue)(item) : null;
68
+ const selectedItem = uniqueValue ? {
69
+ ...item,
70
+ cartDetailValue: uniqueValue,
71
+ isOpenDetailModal: false
72
+ } : item;
73
+ if (needsSpecDetailModal(selectedItem)) {
74
+ const preparedCacheItem = calendarRange ? prepareBookingCacheItem(buildCacheItemFromCartDetail(item, derivedCtx), derivedCtx) : undefined;
64
75
  return {
65
76
  action: 'requiresDetail',
66
- payload: buildRequiresDetailPayload(item, derivedCtx)
77
+ payload: {
78
+ ...buildRequiresDetailPayload(item, derivedCtx),
79
+ ...(preparedCacheItem ? {
80
+ preparedCacheItem
81
+ } : {})
82
+ }
67
83
  };
68
84
  }
69
- const cacheItem = prepareBookingCacheItem(buildCacheItemFromCartDetail(item, derivedCtx), derivedCtx);
85
+ const cacheItem = prepareBookingCacheItem(buildCacheItemFromCartDetail(selectedItem, derivedCtx), derivedCtx);
70
86
  if (needsBookingEdit(cacheItem, derivedCtx)) {
71
87
  return {
72
88
  action: 'requiresBookingEdit',
@@ -146,6 +162,21 @@ function isMultiDayLike(cacheItem) {
146
162
  * `_extend.resource / capacity / startDate / endDate` 等后续 booking mapper 需要的字段。
147
163
  */
148
164
  function prepareBookingCacheItem(cacheItem, ctx) {
165
+ if ((0, _BookingContext.getCalendarBookingRange)(cacheItem, ctx)) {
166
+ if (cacheItem._data?.calendarBookingPreparationKey === (0, _BookingContext.calendarBookingPreparationKey)(cacheItem, ctx)) return cacheItem;
167
+ return (0, _BookingContext.getProductExtend)({
168
+ cacheItem,
169
+ ctx: ctx,
170
+ isDisabledTime: true
171
+ });
172
+ }
173
+ if (ctx?.bookingTimeRangeFromCalendar && (cacheItem.duration?.type === 'days' || cacheItem.duration_type === 'days' || cacheItem._extend?.sub_type === 'days')) {
174
+ ctx = {
175
+ ...ctx,
176
+ bookingTimeRangeFromCalendar: undefined,
177
+ resourceIdFromCalendar: undefined
178
+ };
179
+ }
149
180
  if (ctx?.rememberedTime === undefined && (isNormalBookingProduct(cacheItem) || hasPreparedBookingExtend(cacheItem))) {
150
181
  return cacheItem;
151
182
  }
@@ -0,0 +1,8 @@
1
+ type RecordValue = Record<string, any>;
2
+ /**
3
+ * Resolve a whole SKU only when the original configuration proves one legal
4
+ * result. A default, a stock-filtered remainder, or missing detail is not proof
5
+ * of uniqueness. The input product and its existing selections stay untouched.
6
+ */
7
+ export declare function resolveUniqueCartDetailValue(product: RecordValue): RecordValue | null;
8
+ export {};
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.resolveUniqueCartDetailValue = resolveUniqueCartDetailValue;
7
+ const flag = value => value === true || value === 1 || value === '1';
8
+ const cleared = value => value === false || value === 0 || value === '0';
9
+ const enabled = item => item && !flag(item.disabled) && !cleared(item.is_enabled) && item.deleted_at == null;
10
+ const sellable = item => enabled(item) && (!flag(item.is_track) || flag(item.over_sold) || Number(item.stock_quantity) > 0);
11
+ const bound = (value, fallback = 0) => {
12
+ if (value == null || value === '') return fallback;
13
+ if (typeof value !== 'number' && typeof value !== 'string') return null;
14
+ const number = Number(value);
15
+ return Number.isInteger(number) && number >= 0 ? number : null;
16
+ };
17
+ const validId = value => (typeof value === 'number' || typeof value === 'string') && Number.isSafeInteger(Number(value)) && Number(value) > 0;
18
+
19
+ /** A choice is unique only if its complete allowed quantity interval is one value. */
20
+ function fixedQuantity(minimums, maximums) {
21
+ const min = Math.max(1, ...minimums);
22
+ const max = Math.min(...maximums.filter(value => value > 0), Infinity);
23
+ return min === max ? min : null;
24
+ }
25
+ function configuredGroups(product, key, countKey) {
26
+ const groups = product[key];
27
+ if (groups == null && product[countKey] == null) return null;
28
+ const count = bound(product[countKey]);
29
+ if (count == null || groups != null && !Array.isArray(groups)) return null;
30
+ if (count > 0 && (!Array.isArray(groups) || groups.length !== count)) return null;
31
+ return groups || [];
32
+ }
33
+
34
+ /**
35
+ * Resolve a whole SKU only when the original configuration proves one legal
36
+ * result. A default, a stock-filtered remainder, or missing detail is not proof
37
+ * of uniqueness. The input product and its existing selections stay untouched.
38
+ */
39
+ function resolveUniqueCartDetailValue(product) {
40
+ if (!product || !validId(product.id ?? product.product_id) || flag(product.open_sold_weight)) return null;
41
+ const productId = product.id ?? product.product_id;
42
+ const existing = product.cartDetailValue;
43
+ const hasConfiguredSku = flag(product.is_variant) || Number(product.variant_count) > 0 || Number(product.option_group_count) > 0 || Number(product.bundle_group_count) > 0 || product.option_group?.length > 0 || product.bundle_group?.length > 0 || product.bundle_groups?.length > 0 || product.variant_group?.length > 0;
44
+ if (existing && !hasConfiguredSku && !(existing.option?.length || existing.bundle?.length)) {
45
+ return {
46
+ ...existing,
47
+ product_id: productId,
48
+ quantity: 1
49
+ };
50
+ }
51
+ const knowsVariantShape = cleared(product.is_variant) || product.variant_count === 0 || product.variant_count === '0' || Array.isArray(product.variant) || Array.isArray(product.variant_group);
52
+ if (!knowsVariantShape) return null;
53
+ const optionGroups = configuredGroups(product, 'option_group', 'option_group_count');
54
+ const bundleKey = product.bundle_group != null ? 'bundle_group' : 'bundle_groups';
55
+ const bundleGroups = configuredGroups(product, bundleKey, 'bundle_group_count');
56
+ if (!optionGroups || !bundleGroups) return null;
57
+ const value = {
58
+ ...(product.cartDetailValue || {}),
59
+ product_id: productId,
60
+ product_variant_id: 0,
61
+ option: [],
62
+ bundle: [],
63
+ quantity: 1
64
+ };
65
+ const hasVariant = flag(product.is_variant) || Number(product.variant_count) > 0 || Array.isArray(product.variant_group) && product.variant_group.length > 0 || Array.isArray(product.variant) && product.variant.length > 0;
66
+ if (hasVariant) {
67
+ if (!Array.isArray(product.variant) || product.variant.length !== 1 || Number(product.variant_count) > 0 && Number(product.variant_count) !== 1) return null;
68
+ const [variant] = product.variant;
69
+ if (!validId(variant?.id) || !sellable(variant)) return null;
70
+ value.product_variant_id = variant.id;
71
+ if (variant.price == null || variant.price === '' || !Number.isFinite(Number(variant.price)) || Number(variant.price) < 0) return null;
72
+ value.price = variant.price;
73
+ value.production_code = variant.production_code ?? variant.code ?? '';
74
+ }
75
+ for (const group of optionGroups) {
76
+ // Do not silently remove configured alternatives that are disabled or out of stock.
77
+ if (!validId(group?.id) || !enabled(group) || !Array.isArray(group.option_item) || group.option_item.length !== 1) return null;
78
+ const [item] = group.option_item;
79
+ if (!validId(item?.id) || !sellable(item)) return null;
80
+ const multiple = flag(group.is_multiple);
81
+ const groupMin = bound(group.min_quantity);
82
+ const groupMax = bound(group.max_quantity);
83
+ const itemMin = bound(item.min_quantity);
84
+ const itemMax = bound(item.max_quantity, 1);
85
+ if ([groupMin, groupMax, itemMin, itemMax].some(value => value == null)) return null;
86
+ const advanced = multiple && flag(group.metadata?.advanced_settings_enabled);
87
+ const minTypes = advanced ? bound(group.metadata?.option_types_config?.min) : 0;
88
+ const maxTypes = advanced ? bound(group.metadata?.option_types_config?.max) : 0;
89
+ if (minTypes == null || maxTypes == null || minTypes > 1 || maxTypes > 0 && maxTypes < minTypes) return null;
90
+ const required = multiple ? groupMin > 0 || minTypes > 0 : flag(group.required);
91
+ if (!required) return null;
92
+ const quantity = fixedQuantity([itemMin, ...(multiple ? [groupMin] : [])], [itemMax, ...(multiple ? [groupMax] : [])]);
93
+ if (!quantity) return null;
94
+ const price = item.price ?? item.add_price ?? 0;
95
+ value.option.push({
96
+ ...item,
97
+ id: item.id,
98
+ product_option_item_id: item.id,
99
+ option_group_item_id: item.id,
100
+ option_group_id: group.id,
101
+ product_id: productId,
102
+ quantity,
103
+ num: quantity,
104
+ price,
105
+ original_price: price
106
+ });
107
+ }
108
+ for (const group of bundleGroups) {
109
+ if (!validId(group?.id) || !enabled(group) || !Array.isArray(group.bundle_item) || group.bundle_item.length !== 1) return null;
110
+ const [item] = group.bundle_item;
111
+ if (!validId(item?.id) || !validId(item?.bundle_product_id) || !sellable(item) || item.option_group?.length || item.variant_group?.length || item.variant?.length || item.bundle_group?.length || item.bundle_groups?.length || flag(item.is_variant) || flag(item.open_sold_weight) || Number(item.variant_count) > 0 || Number(item.option_group_count) > 0 || Number(item.bundle_group_count) > 0) return null;
112
+ const groupMin = bound(group.min_quantity);
113
+ const groupMax = bound(group.max_quantity);
114
+ const itemMin = bound(item.min_quantity);
115
+ const itemMax = bound(item.max_quantity);
116
+ if ([groupMin, groupMax, itemMin, itemMax].some(value => value == null) || groupMin <= 0) return null;
117
+ const quantity = fixedQuantity([groupMin, itemMin], [groupMax, itemMax]);
118
+ if (!quantity) return null;
119
+ value.bundle.push({
120
+ ...item,
121
+ id: item.id,
122
+ group_id: group.id,
123
+ bundle_group_id: group.id,
124
+ _bundle_product_id: item.bundle_product_id,
125
+ quantity,
126
+ num: quantity,
127
+ option: []
128
+ });
129
+ }
130
+ const key = [productId, value.product_variant_id, ...value.option.map(item => `o${item.option_group_id}:${item.id}:${item.quantity}`), ...value.bundle.map(item => `b${item.group_id}:${item.id}:${item.quantity}`), ...(value.session ? [`s${value.session.key ?? value.session.id ?? ''}`] : [])].join('_');
131
+ return {
132
+ ...value,
133
+ key,
134
+ rowKey: key
135
+ };
136
+ }
@@ -0,0 +1,8 @@
1
+ import type { GlobalScanHandleResult, GlobalScanHostBridge } from '../../types';
2
+ import { type GlobalScanApplyHost } from './applyGlobalScan';
3
+ import type { GlobalScanFormattedResult } from './formatGlobalScan';
4
+ export interface ProductVoucherCollectionScanHost extends GlobalScanApplyHost {
5
+ loadCustomerDiscounts(): Promise<Record<string, any>[]>;
6
+ }
7
+ /** Resolve the scanned account, then collect all of that customer's vouchers. */
8
+ export declare function applyProductVoucherCollectionScan(host: ProductVoucherCollectionScanHost, formatted: GlobalScanFormattedResult, bridge: GlobalScanHostBridge): Promise<GlobalScanHandleResult>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.applyProductVoucherCollectionScan = applyProductVoucherCollectionScan;
7
+ var _applyGlobalScan = require("./applyGlobalScan");
8
+ /** Resolve the scanned account, then collect all of that customer's vouchers. */
9
+ async function applyProductVoucherCollectionScan(host, formatted, bridge) {
10
+ const assertCurrent = () => {
11
+ if (bridge.isCurrent?.() === false) {
12
+ throw new DOMException('Scan session ended', 'AbortError');
13
+ }
14
+ };
15
+ const isPass = formatted.searchType === 'walletPass';
16
+ // Order numbers and wristbands resolve through batch-search. Their returned
17
+ // passes identify the customer; they are not the collection's voucher list.
18
+ // Resolve source-shop IDs before reusing the wallet customer-binding flow.
19
+ const customerScan = isPass ? {
20
+ ...formatted,
21
+ searchType: 'wallet',
22
+ customerId: formatted.customerId ?? formatted.data?.id ?? formatted.data?.customer_id,
23
+ isCrossShopWallet: true
24
+ } : formatted;
25
+ assertCurrent();
26
+ const result = await (0, _applyGlobalScan.applyGlobalScan)({
27
+ ...host,
28
+ setOrderCustomer: customer => {
29
+ assertCurrent();
30
+ host.setOrderCustomer(customer);
31
+ },
32
+ addProductToOrder: (product, booking) => {
33
+ assertCurrent();
34
+ return host.addProductToOrder(product, booking);
35
+ }
36
+ }, customerScan, {
37
+ ...bridge,
38
+ // Without a switch bridge, do not return the previous customer's vouchers.
39
+ requestCustomerSwitch: bridge.requestCustomerSwitch ?? (async () => false)
40
+ });
41
+ assertCurrent();
42
+ if (customerScan.searchType === 'wallet' && result.status === 'success') {
43
+ const vouchers = await host.loadCustomerDiscounts();
44
+ assertCurrent();
45
+ return {
46
+ ...result,
47
+ redemption: {
48
+ source: isPass ? 'scan' : 'wallet',
49
+ vouchers
50
+ }
51
+ };
52
+ }
53
+ return result;
54
+ }
@@ -10,6 +10,7 @@ exports.searchWalletPass = exports.searchWallet = exports.searchProduct = export
10
10
  const searchWalletPass = async (request, code) => {
11
11
  const params = {
12
12
  code,
13
+ resolve_ticket_order: 1,
13
14
  translate_flag: 1,
14
15
  // 翻译识别码名称 0:不翻译 1:翻译
15
16
  relation_product: 1,
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.handleUniversalScan = exports.handleGlobalScan = exports.handleCustomerScan = void 0;
7
7
  var _cloudSearch = require("./cloudSearch");
8
8
  var _scanCache = _interopRequireDefault(require("./scanCache"));
9
+ var _platform = require("../../../../utils/platform");
9
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
11
  /**
11
12
  * Promise.any 的替代实现
@@ -107,7 +108,7 @@ const handleGlobalScan = (request, localSearch, channel) => {
107
108
  if (value.startsWith('WL')) {
108
109
  requestList = [(0, _cloudSearch.searchWallet)(request, value)];
109
110
  } else {
110
- requestList = [...(channel === 'kiosk' ? [] : [(0, _cloudSearch.searchOrder)(request, value)]), (0, _cloudSearch.searchWalletPass)(request, value), (0, _cloudSearch.searchWallet)(request, value), (0, _cloudSearch.searchProduct)(request, value)];
111
+ requestList = [...((0, _platform.isSelfServicePlatform)(channel) ? [] : [(0, _cloudSearch.searchOrder)(request, value)]), (0, _cloudSearch.searchWalletPass)(request, value), (0, _cloudSearch.searchWallet)(request, value), (0, _cloudSearch.searchProduct)(request, value)];
111
112
  }
112
113
  return requestList;
113
114
  };
@@ -130,9 +130,12 @@ class OrderInvoicePreviewImpl extends _BaseModule.BaseModule {
130
130
  const task = (async () => {
131
131
  const [snapshot, context, template] = await Promise.all([this.loadSource(input), this.loadContext(input), (0, _loadCustomerInvoiceLayout.loadCustomerInvoiceTemplate)(this.request, input)]);
132
132
  const source = (0, _loadPaymentMethods.withPaymentMethodNames)(snapshot, context.methods);
133
- const getData = this.core.getPlugin('app')?.getData?.();
133
+ const appPlugin = this.core.getPlugin('app');
134
+ const getData = appPlugin?.getData?.();
134
135
  if (getData?.('shop_id') != null && String(getData('shop_id')) !== String(input.shopId)) throw new Error('Invoice shop changed');
135
136
  const coreData = getData?.('core');
137
+ const hostApp = appPlugin?.getApp?.();
138
+ const shopCore = hostApp?.models?.getStore?.().getDataByModel?.('core', 'core') || hostApp?.data?.store?.getStore?.().getDataByModel?.('core', 'core') || coreData?.core || coreData || {};
136
139
  const shop = {
137
140
  ...(coreData?.core?.shop || coreData?.shop || {}),
138
141
  ...(getData?.('shop_info') || {}),
@@ -142,6 +145,9 @@ class OrderInvoicePreviewImpl extends _BaseModule.BaseModule {
142
145
  tax_country_code: getData('tax_country_code')
143
146
  } : {})
144
147
  };
148
+ shop.default_domain || (shop.default_domain = shopCore.default_domain);
149
+ shop.private_domain || (shop.private_domain = shopCore.private_domain);
150
+ shop.private_domain_protocol || (shop.private_domain_protocol = shopCore.private_domain_protocol);
145
151
  if (generation !== this.generation || this.disposed) throw new Error('Invoice request superseded');
146
152
  const languageOptions = (0, _customerInvoiceLanguages.resolveCustomerInvoiceLanguages)(template.language, input.locale);
147
153
  const remembered = this.languageSelection?.code;
@@ -101,6 +101,8 @@ export declare class ScanOrderImpl extends BaseSalesImpl implements Module {
101
101
  private buildSubmitPayloadEnhancer;
102
102
  private isScanOrderMoreMode;
103
103
  private submitScanOrderMore;
104
+ /** Read both current and legacy cart snapshots without changing the product catalog. */
105
+ private getMenuAvailabilityProductSources;
104
106
  submitScanOrder<T = any>(): Promise<T>;
105
107
  addProductToOrder(product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity): Promise<import("../../modules/Order/types").OrderProduct[]>;
106
108
  updateOrderProduct(params: UpdateOrderProductParams): Promise<import("../../modules/Order/types").OrderProduct[]>;
@@ -31,6 +31,7 @@ var _getDateIsInSchedule = require("../../modules/Schedule/getDateIsInSchedule")
31
31
  var _utils2 = require("../../modules/Order/utils");
32
32
  var _dayjs = _interopRequireDefault(require("dayjs"));
33
33
  var _itemRule = require("../../model/strategy/adapter/itemRule");
34
+ var _menuAvailability = require("./menuAvailability");
34
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
36
  function isItemRewardProductDiscount(discount) {
36
37
  return discount?.type === 'product' && discount?.metadata?.source === 'promotion' && discount?.metadata?.actionType === 'ITEM_REWARD';
@@ -994,6 +995,27 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
994
995
  }
995
996
  return result;
996
997
  }
998
+
999
+ /** Read both current and legacy cart snapshots without changing the product catalog. */
1000
+ getMenuAvailabilityProductSources(tempOrder) {
1001
+ const products = tempOrder.products || [];
1002
+ const sources = [...this.enabledReservationRuleProducts];
1003
+ for (const product of products) {
1004
+ const uid = product.metadata?.unique_identification_number;
1005
+ const origins = [product._origin, product.metadata?.origin, uid ? tempOrder._extend?.productsByUid?.[String(uid)]?.origin : undefined];
1006
+ for (const origin of origins) {
1007
+ if (origin && typeof origin === 'object' && !Array.isArray(origin)) {
1008
+ sources.push({
1009
+ ...origin,
1010
+ product_id: product.product_id
1011
+ });
1012
+ }
1013
+ }
1014
+ }
1015
+ const cachedSources = this.store.products?.getRawProductPriceSources?.(products.map(product => Number(product.product_id)));
1016
+ if (cachedSources) sources.push(...cachedSources.values());
1017
+ return sources;
1018
+ }
997
1019
  async submitScanOrder() {
998
1020
  this.logMethodStart('submitScanOrder');
999
1021
  try {
@@ -1016,8 +1038,51 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
1016
1038
  delete tempOrderForSubmit.table_number;
1017
1039
  }
1018
1040
  this.store.order.persistTempOrder();
1019
- const enhancePayload = this.buildSubmitPayloadEnhancer();
1020
- const result = this.isScanOrderMoreMode(tempOrderForSubmit) ? await this.submitScanOrderMore({
1041
+ const isAdditionalOrder = this.isScanOrderMoreMode(tempOrderForSubmit);
1042
+ const enhanceBookingPayload = this.buildSubmitPayloadEnhancer();
1043
+ const ruleProduct = this.enabledReservationRuleProducts[0];
1044
+ const resource = this.store.resource;
1045
+ const willAppendRuleProduct = !tempOrderForSubmit.order_id && ruleProduct && String(resource?.relationId ?? '').trim() && resource?.tableFormId;
1046
+ const productsToPrepare = isAdditionalOrder ? tempOrderForSubmit.products.filter(product => product.metadata?.is_rule !== true) : [...tempOrderForSubmit.products, ...(willAppendRuleProduct ? [{
1047
+ product_id: ruleProduct.id,
1048
+ metadata: {
1049
+ is_rule: true
1050
+ }
1051
+ }] : [])];
1052
+ const associatedMenus = this.otherParams?.dineInConfig?.['menu.associated_menus'];
1053
+ if (!Array.isArray(associatedMenus)) {
1054
+ throw new _menuAvailability.ScanOrderMenuAvailabilityError('SCAN_ORDER_MENU_VALIDATION_FAILED');
1055
+ }
1056
+ const validateMenuAvailability = await (0, _menuAvailability.prepareScanOrderMenuAvailability)({
1057
+ request: this.request,
1058
+ menuIds: associatedMenus.map(menu => menu?.value),
1059
+ timezone: String(this.getPickupTimingContextData('timezone') ?? ''),
1060
+ products: productsToPrepare,
1061
+ productSources: this.getMenuAvailabilityProductSources(tempOrderForSubmit)
1062
+ });
1063
+ const enhancePayload = (payload, context) => {
1064
+ const enhancedPayload = enhanceBookingPayload(payload, context);
1065
+ const originalByUid = new Map(context.tempOrder.products.filter(product => product.metadata?.unique_identification_number).map(product => [String(product.metadata.unique_identification_number), product]));
1066
+ const outgoingProducts = isAdditionalOrder ? (0, _utils.filterProductsForScanOrderMore)(enhancedPayload.products) : enhancedPayload.products;
1067
+ // Serialization strips the prefill marker. Restore it only on validation
1068
+ // copies, by line UID, so a manually added row of the same product stays checked.
1069
+ const validationProducts = outgoingProducts.map(product => {
1070
+ const uid = product.metadata?.unique_identification_number;
1071
+ const original = uid ? originalByUid.get(String(uid)) : undefined;
1072
+ return original?.metadata?.item_rule_prefill === true ? {
1073
+ ...product,
1074
+ metadata: {
1075
+ ...product.metadata,
1076
+ item_rule_prefill: true
1077
+ }
1078
+ } : product;
1079
+ });
1080
+ // Both checkout and add-on build their payload after async quotation. Check
1081
+ // the actual outgoing lines using a fresh clock, never the draft schedule_date.
1082
+ validateMenuAvailability(validationProducts, this.getMenuAvailabilityProductSources(context.tempOrder));
1083
+ return enhancedPayload;
1084
+ };
1085
+ const result = isAdditionalOrder ? await this.submitScanOrderMore({
1021
1086
  tempOrder: tempOrderForSubmit,
1022
1087
  enhancePayload
1023
1088
  }) : await this.submitSalesOrder({
@@ -2113,6 +2178,11 @@ class ScanOrderImpl extends _BaseSales.BaseSalesImpl {
2113
2178
  tempOrder.resource_id = normalizedResourceId;
2114
2179
  tempOrder.relation_id = (0, _utils.toPositiveString)(occupyDetail?.form_record_id) || normalizedResourceId || tempOrder.relation_id;
2115
2180
  tempOrder.table_form_id = (0, _utils.toPositiveString)(occupyDetail?.form_id) || tempOrder.table_form_id;
2181
+ // 冲突后转加餐需同步模式,否则重试仍会携带整单数据走 checkout。
2182
+ const resourceState = this.store.resource ?? this.normalizeResourceState(occupyDetail, resourceSelectType, true);
2183
+ resourceState.mode = 'additional_order';
2184
+ resourceState.order_id = result.order_id;
2185
+ this.store.resource = resourceState;
2116
2186
  this.store.order?.persistTempOrder();
2117
2187
  this.logMethodSuccess('syncAdditionalOrderFromResource', {
2118
2188
  ...result,
@@ -0,0 +1,24 @@
1
+ type Product = Record<string, any>;
2
+ type Request = {
3
+ get: (url: string, data?: any, options?: any) => Promise<any>;
4
+ post: (url: string, data?: any, options?: any) => Promise<any>;
5
+ };
6
+ export type ScanOrderMenuAvailabilityErrorCode = 'SCAN_ORDER_MENU_UNAVAILABLE' | 'SCAN_ORDER_MENU_VALIDATION_FAILED';
7
+ export declare class ScanOrderMenuAvailabilityError extends Error {
8
+ readonly code: ScanOrderMenuAvailabilityErrorCode;
9
+ readonly productIds: number[];
10
+ constructor(code: ScanOrderMenuAvailabilityErrorCode, productIds?: number[]);
11
+ }
12
+ export type ScanOrderMenuAvailabilityValidator = (products: Product[], productSources?: Product[]) => void;
13
+ /**
14
+ * Prepare fresh menu definitions without changing ProductList or the cart. The
15
+ * returned validator reads the shop's current time again at the submission boundary.
16
+ */
17
+ export declare function prepareScanOrderMenuAvailability({ request, menuIds, timezone, products, productSources, }: {
18
+ request: Request;
19
+ menuIds: Array<number | string>;
20
+ timezone: string;
21
+ products: Product[];
22
+ productSources?: Product[];
23
+ }): Promise<ScanOrderMenuAvailabilityValidator>;
24
+ export {};