@pisell/pisellos 2.3.124 → 2.3.125

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 (93) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  2. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +2 -4
  4. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +19 -58
  5. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +12 -24
  6. package/dist/modules/Customer/index.js +3 -6
  7. package/dist/modules/Customer/types.d.ts +0 -2
  8. package/dist/modules/Discount/index.d.ts +2 -2
  9. package/dist/modules/Discount/index.js +151 -37
  10. package/dist/modules/Discount/types.d.ts +5 -36
  11. package/dist/modules/Order/index.d.ts +13 -8
  12. package/dist/modules/Order/index.js +307 -432
  13. package/dist/modules/Order/types.d.ts +5 -0
  14. package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
  15. package/dist/modules/Order/utils.d.ts +11 -1
  16. package/dist/modules/Order/utils.js +127 -122
  17. package/dist/modules/Payment/types.d.ts +1 -21
  18. package/dist/modules/Payment/types.js +0 -2
  19. package/dist/modules/Payment/walletpass.d.ts +1 -1
  20. package/dist/modules/Payment/walletpass.js +47 -80
  21. package/dist/modules/Rules/index.d.ts +2 -2
  22. package/dist/modules/Rules/index.js +186 -480
  23. package/dist/modules/Rules/types.d.ts +0 -4
  24. package/dist/server/modules/order/types.d.ts +0 -2
  25. package/dist/solution/BaseSales/index.d.ts +0 -1
  26. package/dist/solution/BaseSales/index.js +59 -51
  27. package/dist/solution/BaseSales/types.d.ts +2 -2
  28. package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
  29. package/dist/solution/BookingByStep/index.d.ts +1 -1
  30. package/dist/solution/BookingTicket/index.d.ts +2 -1
  31. package/dist/solution/BookingTicket/index.js +63 -60
  32. package/dist/solution/BookingTicket/types.d.ts +1 -5
  33. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  34. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
  35. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  36. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  37. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
  38. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  39. package/dist/solution/ShopDiscount/index.js +42 -99
  40. package/dist/solution/ShopDiscount/utils.d.ts +2 -4
  41. package/dist/solution/ShopDiscount/utils.js +23 -43
  42. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  43. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  44. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  45. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  46. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
  47. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
  48. package/lib/modules/Customer/index.js +1 -5
  49. package/lib/modules/Customer/types.d.ts +0 -2
  50. package/lib/modules/Discount/index.d.ts +2 -2
  51. package/lib/modules/Discount/index.js +129 -23
  52. package/lib/modules/Discount/types.d.ts +5 -36
  53. package/lib/modules/Order/index.d.ts +13 -8
  54. package/lib/modules/Order/index.js +107 -215
  55. package/lib/modules/Order/types.d.ts +5 -0
  56. package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
  57. package/lib/modules/Order/utils.d.ts +11 -1
  58. package/lib/modules/Order/utils.js +45 -39
  59. package/lib/modules/Payment/types.d.ts +1 -21
  60. package/lib/modules/Payment/types.js +0 -1
  61. package/lib/modules/Payment/walletpass.d.ts +1 -1
  62. package/lib/modules/Payment/walletpass.js +9 -29
  63. package/lib/modules/Rules/index.d.ts +2 -2
  64. package/lib/modules/Rules/index.js +110 -357
  65. package/lib/modules/Rules/types.d.ts +0 -4
  66. package/lib/server/modules/order/types.d.ts +0 -2
  67. package/lib/solution/BaseSales/index.d.ts +0 -1
  68. package/lib/solution/BaseSales/index.js +12 -5
  69. package/lib/solution/BaseSales/types.d.ts +2 -2
  70. package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
  71. package/lib/solution/BookingByStep/index.d.ts +1 -1
  72. package/lib/solution/BookingTicket/index.d.ts +2 -1
  73. package/lib/solution/BookingTicket/index.js +33 -36
  74. package/lib/solution/BookingTicket/types.d.ts +1 -5
  75. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  76. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
  77. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  78. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  79. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
  80. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  81. package/lib/solution/ShopDiscount/index.js +9 -55
  82. package/lib/solution/ShopDiscount/utils.d.ts +2 -4
  83. package/lib/solution/ShopDiscount/utils.js +25 -42
  84. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  85. package/package.json +1 -1
  86. package/dist/modules/Discount/availability.d.ts +0 -7
  87. package/dist/modules/Discount/availability.js +0 -49
  88. package/dist/modules/Discount/entitlementPass.d.ts +0 -34
  89. package/dist/modules/Discount/entitlementPass.js +0 -147
  90. package/lib/modules/Discount/availability.d.ts +0 -7
  91. package/lib/modules/Discount/availability.js +0 -43
  92. package/lib/modules/Discount/entitlementPass.d.ts +0 -34
  93. package/lib/modules/Discount/entitlementPass.js +0 -141
@@ -7,7 +7,6 @@ exports.buildCacheItemFromOrderLine = buildCacheItemFromOrderLine;
7
7
  var _dayjs = _interopRequireDefault(require("dayjs"));
8
8
  var _utils = require("../../Order/utils");
9
9
  var _manualProductDiscount = require("../../Order/utils/manualProductDiscount");
10
- var _entitlementPass = require("../../Discount/entitlementPass");
11
10
  var _orderLineDisplay = require("./orderLineDisplay");
12
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
12
  function safeFormat(value, fmt) {
@@ -117,38 +116,11 @@ function resolveProductTitle(product, booking, sourceProduct) {
117
116
  function resolveProductCover(product, booking, sourceProduct) {
118
117
  return sourceProduct?.cover ?? product.product_cover ?? '';
119
118
  }
120
- function toFinitePrice(value) {
121
- if (value === undefined || value === null || value === '') return null;
122
- const parsed = Number(value);
123
- return Number.isFinite(parsed) ? parsed : null;
124
- }
125
- function hasEntitlementPassDiscount(product) {
126
- const hasEntitlementDiscount = discountList => Array.isArray(discountList) && discountList.some(_entitlementPass.isEntitlementPass);
127
- return hasEntitlementDiscount(product.discount_list) || Array.isArray(product.product_bundle) && product.product_bundle.some(bundle => hasEntitlementDiscount(bundle?.discount_list));
128
- }
129
- function resolveMainProductPrice(product, fallback, sourceProduct, restoreEntitlementPrice = false) {
119
+ function resolveMainProductPrice(product, fallback) {
130
120
  const metadata = product.metadata || {};
131
- if (!restoreEntitlementPrice) {
132
- const value = metadata.main_product_original_price ?? metadata.source_product_price;
133
- const parsed = Number(value);
134
- return Number.isFinite(parsed) ? parsed : fallback;
135
- }
136
- const sourcePrice = toFinitePrice(metadata.source_product_price);
137
- if (sourcePrice !== null) return sourcePrice;
138
- const variantId = Number(product.product_variant_id || 0);
139
- const variantList = sourceProduct?.variant ?? metadata.origin?.variant;
140
- if (variantId > 0 && Array.isArray(variantList)) {
141
- const matched = variantList.find(variant => Number(variant?.id) === variantId);
142
- const variantPrice = toFinitePrice(matched?.price ?? matched?.base_price);
143
- if (variantPrice !== null) return variantPrice;
144
- }
145
- const catalogPrice = toFinitePrice(sourceProduct?.price ?? sourceProduct?.base_price ?? metadata.origin?.price ?? metadata.origin?.base_price);
146
- if (catalogPrice !== null) return catalogPrice;
147
-
148
- // legacy 数据没有 source_product_price 时,main_product_original_price
149
- // 仍比已被月卡改写为 0 的 selling_price 更可靠。
150
- const legacyMainPrice = toFinitePrice(metadata.main_product_original_price);
151
- return legacyMainPrice ?? fallback;
121
+ const value = metadata.main_product_original_price ?? metadata.source_product_price;
122
+ const parsed = Number(value);
123
+ return Number.isFinite(parsed) ? parsed : fallback;
152
124
  }
153
125
  function mapOrderBundleToOtherBundle(bundle) {
154
126
  return bundle.map(item => {
@@ -213,8 +185,7 @@ function buildCacheItemFromOrderLine(input) {
213
185
  const resolvedId = product.product_id ?? sourceProduct?.id;
214
186
  const selling = Number(product.selling_price ?? 0);
215
187
  const original = Number(product.original_price ?? selling);
216
- const shouldRestoreEntitlementPrice = hasEntitlementPassDiscount(product);
217
- const mainProductPrice = resolveMainProductPrice(product, selling, sourceProduct, shouldRestoreEntitlementPrice);
188
+ const mainProductPrice = resolveMainProductPrice(product, selling);
218
189
  const startDate = safeFormat(booking.start_date, 'YYYY-MM-DD');
219
190
  const endDate = safeFormat(booking.end_date, 'YYYY-MM-DD');
220
191
  const startTime = normalizeTimeString(booking.start_time);
@@ -269,7 +240,7 @@ function buildCacheItemFromOrderLine(input) {
269
240
  }
270
241
  }
271
242
  if (product.metadata?.price_override != null || manualDiscount) {
272
- extend.priceOverride = shouldRestoreEntitlementPrice ? product.metadata?.price_override ?? selling : selling;
243
+ extend.priceOverride = selling;
273
244
  }
274
245
  if (booking.holder !== undefined) {
275
246
  extend.holder = booking.holder;
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.buildNormalProductCacheItemFromOrderLine = buildNormalProductCacheItemFromOrderLine;
7
7
  var _utils = require("../../Order/utils");
8
- var _entitlementPass = require("../../Discount/entitlementPass");
9
8
  var _orderLineDisplay = require("./orderLineDisplay");
10
9
  /**
11
10
  * 从已加车的普通商品 order line 反查 SkuDetailModal edit 所需的 cacheItem。
@@ -45,16 +44,12 @@ function resolveSourceProductPrice(product, sourceProduct) {
45
44
  }
46
45
  return Number(product.selling_price ?? 0);
47
46
  }
48
- function hasEntitlementPassDiscount(product) {
49
- const hasEntitlementDiscount = discountList => Array.isArray(discountList) && discountList.some(_entitlementPass.isEntitlementPass);
50
- return hasEntitlementDiscount(product.discount_list) || Array.isArray(product.product_bundle) && product.product_bundle.some(bundle => hasEntitlementDiscount(bundle?.discount_list));
51
- }
52
47
 
53
48
  /** 订单行 bundle → booking other.bundle(保留 original_price 供 setProductPrice 按比例分摊) */
54
- function mapOrderBundleToOtherBundle(bundle, preferManualPrice = false) {
49
+ function mapOrderBundleToOtherBundle(bundle) {
55
50
  return bundle.map(item => {
56
51
  const catalogOriginal = item.original_price ?? item.product_price ?? item.price ?? item.bundle_selling_price;
57
- const selling = preferManualPrice ? item.price ?? item.bundle_selling_price ?? catalogOriginal : item.bundle_selling_price ?? item.price ?? catalogOriginal;
52
+ const selling = item.bundle_selling_price ?? item.price ?? catalogOriginal;
58
53
  const {
59
54
  bundle_selling_price: _omitBundleSelling,
60
55
  ...rest
@@ -83,11 +78,9 @@ function buildNormalProductCacheItemFromOrderLine(input) {
83
78
  const selling = Number(product.selling_price ?? 0);
84
79
  const original = Number(product.original_price ?? selling);
85
80
  const uid = product.metadata?.unique_identification_number;
86
- const originExtend = product.metadata?.origin?._extend;
87
- const shouldPreserveEntitlementPriceOverride = hasEntitlementPassDiscount(product) && (originExtend?.priceOverride !== undefined || product.metadata?.price_override != null);
88
- const hasPriceOverride = originExtend?.priceOverride !== undefined || shouldPreserveEntitlementPriceOverride;
89
81
  const option = (0, _utils.getProductSkuOptions)(product);
90
- const bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : [], shouldPreserveEntitlementPriceOverride);
82
+ const bundle = mapOrderBundleToOtherBundle(Array.isArray(product.product_bundle) ? product.product_bundle : []);
83
+ const originExtend = product.metadata?.origin?._extend;
91
84
  const productOptionString = (0, _orderLineDisplay.buildProductOptionStringFromOrderLine)(product);
92
85
  const discountList = product.discount_list || [];
93
86
  const other = {
@@ -121,8 +114,8 @@ function buildNormalProductCacheItemFromOrderLine(input) {
121
114
  ...(productOptionString ? {
122
115
  product_option_string: productOptionString
123
116
  } : {}),
124
- ...(hasPriceOverride ? {
125
- priceOverride: shouldPreserveEntitlementPriceOverride ? originExtend?.priceOverride ?? product.metadata?.price_override : originExtend?.priceOverride
117
+ ...(originExtend?.priceOverride !== undefined ? {
118
+ priceOverride: originExtend.priceOverride
126
119
  } : {}),
127
120
  ...(originExtend?.bundle_edit !== undefined ? {
128
121
  bundle_edit: originExtend.bundle_edit
@@ -150,14 +150,10 @@ class CustomerModule extends _BaseModule.BaseModule {
150
150
  with: ['latestWalletDetail.wallet', 'contactsInfo', 'formRecord'],
151
151
  search_wallet_flag: 1,
152
152
  search_wallet_pass_flag: 1,
153
- filter_franchisor_permissions: ['use'],
154
153
  ...(search && {
155
154
  search
156
155
  }),
157
- ..._otherParams,
158
- ...(url === '/customer/select-list' ? {
159
- with_franchisor_data: 1
160
- } : {})
156
+ ..._otherParams
161
157
  };
162
158
  const res = await this.request.get(url, queryParams, {
163
159
  cache: {
@@ -50,8 +50,6 @@ export interface ShopGetCustomerListParams {
50
50
  search_wallet_flag?: 0 | 1;
51
51
  /** wallet pass搜索标识 */
52
52
  search_wallet_pass_flag?: 0 | 1;
53
- /** 是否查询连锁加盟组合店铺数据 */
54
- with_franchisor_data?: boolean | 0 | 1;
55
53
  /** 其他筛选参数 */
56
54
  [key: string]: any;
57
55
  }
@@ -25,8 +25,6 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
25
25
  with_wallet_pass_holder: 0 | 1;
26
26
  with_available_wallet_flag?: 0 | 1;
27
27
  with_available_wallet_pass_flag?: 0 | 1;
28
- with_entitlement_pass?: 0 | 1;
29
- filter_order_wallet_pass_usage?: 0 | 1;
30
28
  with_virtual_currency?: 0 | 1;
31
29
  request_timezone: string;
32
30
  order_id?: number | string;
@@ -38,7 +36,9 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
38
36
  }): Promise<DiscountWithReason>;
39
37
  batchSearchByProductIds(productIds: number[]): Promise<any>;
40
38
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
39
+ private checkUsageCreditsLimit;
41
40
  filterEnabledDiscountListWithReason(discountList: Discount[]): DiscountWithReason;
41
+ private checkUsageCreditsLimitWithFailKey;
42
42
  uniqueByProductId(discountList: Discount[]): Discount[];
43
43
  filterDiscountListByProductIds(discountList: Discount[], productIds: number[]): Discount[];
44
44
  calcDiscountApplicableProductTotalPrice(discount: Discount): number | undefined;
@@ -8,7 +8,6 @@ var _utils = require("../../solution/ShopDiscount/utils");
8
8
  var _BaseModule = require("../BaseModule");
9
9
  var _types = require("./types");
10
10
  var _decimal = _interopRequireDefault(require("decimal.js"));
11
- var _availability = require("./availability");
12
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
12
  class DiscountModule extends _BaseModule.BaseModule {
14
13
  defaultName = 'discount';
@@ -84,13 +83,7 @@ class DiscountModule extends _BaseModule.BaseModule {
84
83
  with_available_wallet_pass_flag: params.with_available_wallet_pass_flag ?? 1,
85
84
  with_virtual_currency: params.with_virtual_currency ?? 1
86
85
  });
87
- const entitlementPassList = prepareConfig?.data?.entitlement_pass_list || [];
88
- const entitlementPassIds = new Set(entitlementPassList.map(discount => discount?.id).filter(id => id !== undefined && id !== null).map(id => String(id)));
89
- const excludeEntitlementDuplicates = discount => {
90
- const id = discount?.id;
91
- return id === undefined || id === null || !entitlementPassIds.has(String(id));
92
- };
93
- const rawDiscountList = [...entitlementPassList, ...(prepareConfig?.data?.good_pass_list || []).filter(excludeEntitlementDuplicates), ...(prepareConfig?.data?.discount_card_list || []).filter(excludeEntitlementDuplicates)];
86
+ const rawDiscountList = [...(prepareConfig?.data?.good_pass_list || []), ...(prepareConfig?.data?.discount_card_list || [])];
94
87
  const availableWalletList = [...(prepareConfig?.data?.avaiable_wallet_list || []), ...(prepareConfig?.data?.available_wallet_list || [])];
95
88
  const availableWalletPassList = prepareConfig?.data?.available_wallet_pass_list || [];
96
89
  const availableWalletIds = this.normalizePositiveNumberIds([...availableWalletList.map(item => item?.wallet_id), ...availableWalletPassList.map(item => item?.product_id)]);
@@ -142,7 +135,7 @@ class DiscountModule extends _BaseModule.BaseModule {
142
135
  const result = await this.request.get(`/machinecode/batch-search`, {
143
136
  code,
144
137
  translate_flag: 1,
145
- tags: ['entitlement_pass', 'good_pass', 'product_discount_card'],
138
+ tags: ['good_pass', 'product_discount_card'],
146
139
  // available: 1,
147
140
  relation_product: 1,
148
141
  with: ['extensionData', 'customScheduleSnapshot', 'holder.detail'],
@@ -161,30 +154,143 @@ class DiscountModule extends _BaseModule.BaseModule {
161
154
  const result = await this.request.get(`/machinecode/batch-search`, {
162
155
  ids: productIds,
163
156
  translate_flag: 1,
164
- tags: ['entitlement_pass', 'good_pass', 'product_discount_card'],
165
- relation_product: 1,
166
- with: ['extensionData', 'customScheduleSnapshot', 'holder.detail'],
167
- unified_status_info_flag: 1,
168
- request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
157
+ tags: ['good_pass', 'product_discount_card'],
158
+ relation_product: 1
169
159
  });
170
160
  return result?.data || [];
171
161
  }
172
-
173
- // 展示列表只剔除已失效项,当前不可用项保留并携带原因。
174
162
  filterEnabledDiscountList(discountList) {
175
- return discountList.filter(discount => discount.limit_status === 'enable' && (0, _availability.hasAvailableDiscountBalance)(discount) && !(0, _availability.getDiscountLifecycleReason)(discount)).map(discount => ({
176
- ...discount,
177
- usageLimitFailKey: (0, _availability.getDiscountUsageLimitFailKey)(discount),
178
- reasonCode: (0, _availability.getDiscountUsageBlockReason)(discount)
179
- }));
163
+ return discountList.filter(discount => discount.limit_status === 'enable' && new _decimal.default(discount?.par_value || 0).minus(new _decimal.default(discount?.used_par_value || 0)).greaterThan(0) && this.checkUsageCreditsLimit(discount));
180
164
  }
165
+
166
+ // 检查使用次数限制
167
+ checkUsageCreditsLimit(discount) {
168
+ // 如果没有 extension_data,则不需要限制
169
+ if (!discount.extension_data || discount.extension_data.length === 0) {
170
+ return true;
171
+ }
172
+
173
+ // 查找 field_key 为 usage_credits 的数据
174
+ const usageCreditsData = discount.extension_data.find(data => data.field_key === 'usage_credits');
175
+
176
+ // 如果没有找到 usage_credits 数据,则不需要限制
177
+ if (!usageCreditsData) {
178
+ return true;
179
+ }
180
+ const value = usageCreditsData.value;
181
+
182
+ // 检查总次数限制
183
+ if (value.total_credits && value.total_credits > 0) {
184
+ if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
185
+ return false;
186
+ }
187
+ }
188
+
189
+ // 检查单用户限制
190
+ if (value.per_user_limit && value.per_user_limit > 0) {
191
+ if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
192
+ return false;
193
+ }
194
+ }
195
+
196
+ // 检查单日限制
197
+ if (value.max_per_day && value.max_per_day > 0) {
198
+ if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
199
+ return false;
200
+ }
201
+ }
202
+
203
+ // 检查单周限制
204
+ if (value.max_per_week && value.max_per_week > 0) {
205
+ if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
206
+ return false;
207
+ }
208
+ }
209
+
210
+ // 检查单月限制
211
+ if (value.max_per_month && value.max_per_month > 0) {
212
+ if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
213
+ return false;
214
+ }
215
+ }
216
+
217
+ // 所有检查都通过
218
+ return true;
219
+ }
220
+
221
+ // 过滤启用且可用的优惠券,并返回校验失败原因
181
222
  filterEnabledDiscountListWithReason(discountList) {
223
+ let lists = discountList.filter(discount => discount.limit_status === 'enable').filter(discount => {
224
+ const remaining = new _decimal.default(discount?.par_value || 0).minus(new _decimal.default(discount?.used_par_value || 0)).greaterThan(0);
225
+ return remaining;
226
+ }).map(discount => {
227
+ const limitFailKey = this.checkUsageCreditsLimitWithFailKey(discount);
228
+ return {
229
+ ...discount,
230
+ usageLimitFailKey: limitFailKey
231
+ };
232
+ });
233
+
234
+ // 可用的列表
235
+ const availableLists = lists.filter(item => !item.usageLimitFailKey && item.unified_available_status !== 0);
236
+ // 不可用数据
237
+ const currentFailDiscount = lists.find(item => item.usageLimitFailKey);
182
238
  return {
183
- discountList: this.filterEnabledDiscountList(discountList),
184
- unavailableReasonKey: discountList.map(_availability.getDiscountUsageLimitFailKey).find(key => key !== null) || null
239
+ discountList: availableLists,
240
+ unavailableReasonKey: currentFailDiscount?.usageLimitFailKey
185
241
  };
186
242
  }
187
243
 
244
+ // 检查使用次数限制,并返回校验失败原因
245
+ checkUsageCreditsLimitWithFailKey(discount) {
246
+ if (!discount.extension_data || discount.extension_data.length === 0) {
247
+ return null;
248
+ }
249
+ const usageCreditsData = discount.extension_data.find(data => data.field_key === 'usage_credits');
250
+ if (!usageCreditsData) {
251
+ return null;
252
+ }
253
+ const value = usageCreditsData.value;
254
+
255
+ // 总次数限制
256
+ if (value.total_credits && value.total_credits > 0) {
257
+ if ((discount.total_order_behavior_count || 0) >= value.total_credits) {
258
+ return 'total_credits';
259
+ }
260
+ }
261
+
262
+ // 单用户限制
263
+ if (value.per_user_limit && value.per_user_limit > 0) {
264
+ if ((discount.customer_order_behavior_count || 0) >= value.per_user_limit) {
265
+ return 'per_user_limit';
266
+ }
267
+ }
268
+
269
+ // 单日限制
270
+ if (value.max_per_day && value.max_per_day > 0) {
271
+ if ((discount.today_order_behavior_count || 0) >= value.max_per_day) {
272
+ return 'max_per_day';
273
+ }
274
+ }
275
+
276
+ // 单周限制
277
+ if (value.max_per_week && value.max_per_week > 0) {
278
+ if ((discount.week_order_behavior_count || 0) >= value.max_per_week) {
279
+ return 'max_per_week';
280
+ }
281
+ }
282
+
283
+ // 单月限制
284
+ if (value.max_per_month && value.max_per_month > 0) {
285
+ if ((discount.month_order_behavior_count || 0) >= value.max_per_month) {
286
+ return 'max_per_month';
287
+ }
288
+ }
289
+
290
+ // 全部通过
291
+ return null;
292
+ }
293
+
188
294
  // 根据productIds去重
189
295
  uniqueByProductId(discountList) {
190
296
  return (0, _utils.uniqueById)(discountList, 'product_id');
@@ -44,10 +44,7 @@ interface ApplicableProductDetails {
44
44
  original_amount: string;
45
45
  num: number;
46
46
  metadata?: {
47
- encoded?: string;
48
47
  product_discount_difference?: number;
49
- /** 月卡扣除本单新增使用后的剩余次数;不限次数时为 null。 */
50
- balance?: number | null;
51
48
  };
52
49
  discount?: {
53
50
  fixed_amount?: number;
@@ -66,13 +63,6 @@ interface UsageCreditsValue {
66
63
  max_per_week: number;
67
64
  max_per_month: number;
68
65
  }
69
- export type IncludedUses = {
70
- type: 'limited';
71
- value: number;
72
- } | {
73
- type: 'unlimited';
74
- value: null;
75
- };
76
66
  export type DiscountFilterRejectKey = 'total_credits' | 'per_user_limit' | 'max_per_day' | 'max_per_week' | 'max_per_month';
77
67
  export interface DiscountWithReason {
78
68
  discountList: Discount[];
@@ -117,37 +107,30 @@ interface ExtensionData {
117
107
  }
118
108
  export interface Discount {
119
109
  id: number;
120
- shop_id?: number;
121
110
  product_name: string;
122
111
  encoded: string;
123
112
  code: string;
124
113
  tag: string;
125
- expire_time?: string | null;
126
- expire_date?: string | null;
127
- end_time?: string | null;
114
+ expire_time?: string;
128
115
  product_id: number;
129
116
  relation_type: string;
130
117
  par_value: string;
131
118
  used_par_value: string;
132
119
  limit_status: string;
133
120
  limited_relation_product_data: Limitedrelationproductdata;
134
- balance?: string | number | null;
135
- available_num?: number;
136
- available_products_info?: any[];
121
+ balance: string;
137
122
  format_title: Formattitle;
138
123
  metadata?: {
139
- encoded?: string;
140
124
  discount_card_type?: 'fixed_amount' | 'percent';
141
125
  custom_product_bundle_map_id?: string;
142
126
  validity_type?: "custom_schedule_validity" | "fixed_validity";
143
- included_uses?: IncludedUses;
144
- discount_calculation_mode?: 'item_level' | 'order_level';
145
- holder?: {
127
+ discount_calculation_mode: 'item_level' | 'order_level';
128
+ holder: {
146
129
  type: "customer" | "custom";
147
130
  };
148
131
  };
149
132
  product: Product;
150
- type?: "product" | 'good_pass' | 'entitlement_pass' | 'discount_card' | 'product_discount_card';
133
+ type: "product" | 'good_pass';
151
134
  resource_id?: number;
152
135
  savedAmount?: number;
153
136
  isEditMode?: boolean;
@@ -180,17 +163,9 @@ export interface Discount {
180
163
  applicableProductIds?: number[];
181
164
  applicableProductDetails: ApplicableProductDetails[];
182
165
  appliedProductDetails: ApplicableProductDetails[];
183
- /** Entitlement Pass 编辑订单时已经提交的使用明细。 */
184
- committedAppliedProductDetails?: ApplicableProductDetails[];
185
166
  isDisabledForProductUsed?: boolean;
186
167
  amount?: number;
187
168
  customer_id?: number | string | null;
188
- holder?: {
189
- holder_type?: 'customer' | 'form' | string;
190
- holder_id?: number | string | Array<number | string>;
191
- created_at?: string | null;
192
- [key: string]: any;
193
- };
194
169
  extension_data?: ExtensionData[];
195
170
  total_order_behavior_count?: number;
196
171
  today_order_behavior_count?: number;
@@ -205,12 +180,6 @@ export interface Discount {
205
180
  start_time?: string;
206
181
  discount_rule_uncheck_flag?: boolean;
207
182
  usageLimitFailKey?: string | null;
208
- /** 本次规则计算的不可用原因;可用性恢复后清除。 */
209
- reason?: string;
210
- reasonCode?: string;
211
- unified_messages?: {
212
- title?: string | Record<string, string>;
213
- };
214
183
  unified_available_status?: number | undefined | null;
215
184
  }
216
185
  export interface DiscountState {
@@ -3,7 +3,7 @@ import { BaseModule } from '../BaseModule';
3
3
  import { OrderModuleAPI, CommitOrderParams, UpdateOrderBookingParams, UpdateOrderProductParams, UpdateOrderProductQuantityParams, CancelOrderParams, ChangeBookingStatusParams, CheckoutOrderParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
5
  import { type SubmitPayloadEnhancer } from './utils';
6
- import type { OrderAmountSnapshot, AddProductBookingInput, AddProductToOrderOptions, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, ReplaceTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, ShopServiceData, ShopServiceType } from './types';
6
+ import type { OrderAmountSnapshot, AddProductBookingInput, AddProductToOrderOptions, OrderIdentitySnapshot, OrderPaymentSource, OrderSnapshot, OrderSyncState, SyncPaymentsToOrderParams, SyncPaymentsToOrderResult, SubmitSalesOrderParams, OrderProduct, OrderProductIdentity, OrderSummary, OrderTempOrder, OrderPaymentData, OrderPaymentUpdateOptions, OrderPaymentUpdateResult, SendCustomerPayLinkParams, UpdateTempOrderCustomerInput, OrderCustomerPatch, OrderCustomerView, ReplaceTempOrderOptions, OrderPromotionEvaluator, OrderGiftSelectResolver, OrderUnfulfilledPromotion, OrderLastGiftActions, RemoveProductsFromOrderOptions, SalesNote, SalesNotesMutationSnapshot, SetSalesNoteInput, PickupReferenceMode, PointCardSnapshotMergeContext, PointCardSnapshotItem, ShopServiceData, ShopServiceType } from './types';
7
7
  import type { ICustomer } from '../AccountList/types';
8
8
  import type { Discount } from '../Discount/types';
9
9
  import { UnavailableReason } from '../Rules/types';
@@ -22,6 +22,8 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
22
22
  private sessionStorageRestoreRecord;
23
23
  /** 只允许当前订单最新的 prepare/config 请求回写客户资产态。 */
24
24
  private customerWalletPrepareConfigEpoch;
25
+ /** Payment 可能早于 prepare/config 返回;先按实例 ID 暂存卡号等待 Snapshot。 */
26
+ private pointCardSnapshotCodeCandidates;
25
27
  private salesSummaryModuleName;
26
28
  private rulesHooksOverride?;
27
29
  private moduleHooksOverride?;
@@ -108,7 +110,6 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
108
110
  }>;
109
111
  applyDiscount(options?: {
110
112
  reapplyBookingDiscountProductUids?: string[];
111
- preferredEntitlementPassIds?: number[];
112
113
  }): void;
113
114
  /**
114
115
  * 注入促销评估器。
@@ -188,7 +189,16 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
188
189
  private clearTempOrderCustomerWalletSnapshots;
189
190
  private clearCustomerWalletState;
190
191
  private clearCustomerWalletRuntimeState;
192
+ private rememberPointCardSnapshotCodeCandidates;
193
+ private getRememberedPointCardSnapshotCodeCandidates;
194
+ private getPointCardSnapshotOrderIdentityKey;
195
+ private isPointCardSnapshotMergeContextCurrent;
191
196
  private writeCustomerWalletSnapshotsFromPrepareConfig;
197
+ /**
198
+ * 将 Payment WalletPass 返回的实例 code 回填到当前订单 Snapshot。
199
+ * 这里只按资产 ID 补空值,不新增卡、不覆盖 prepare/config 冻结的余额。
200
+ */
201
+ mergePointCardSnapshotCodes(walletPassList: unknown, context?: PointCardSnapshotMergeContext): PointCardSnapshotItem[];
192
202
  private createExternalSaleNumber;
193
203
  private ensureExternalSaleNumber;
194
204
  private ensureRequestUniqueIdempotencyToken;
@@ -478,12 +488,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
478
488
  }>, options?: {
479
489
  skipEditDiscountConfigRefresh?: boolean;
480
490
  }): Promise<OrderProduct[]>;
481
- private getFullCoveragePassDiscounts;
482
- private hasEntitlementPassDiscount;
483
491
  private hasGoodPassDiscount;
484
- private isPersistedProductLine;
485
- private isRuntimeEntitlementAppend;
486
- private hasSameEntitlementMergePriceConfig;
487
492
  private getBundleRuntimeIdentity;
488
493
  private preservePersistedBundlePriceFields;
489
494
  private applyOrderProductUpdateToTempOrder;
@@ -573,7 +578,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
573
578
  generateIdempotencyToken(): string;
574
579
  syncPaymentsToOrder<T = any>(params: SyncPaymentsToOrderParams): Promise<SyncPaymentsToOrderResult<T>>;
575
580
  createOrder(params: CommitOrderParams['query']): {
576
- type: "appointment_booking" | "virtual";
581
+ type: "virtual" | "appointment_booking";
577
582
  platform: string;
578
583
  sales_channel: string;
579
584
  order_sales_channel: string;