@pisell/pisellos 2.3.127 → 2.3.128

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 (103) 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 +2 -7
  12. package/dist/modules/Order/index.js +331 -480
  13. package/dist/modules/Order/utils/orderCollectionIdentity.js +12 -16
  14. package/dist/modules/Order/utils/weighedProduct.d.ts +12 -0
  15. package/dist/modules/Order/utils/weighedProduct.js +94 -0
  16. package/dist/modules/Order/utils.d.ts +1 -1
  17. package/dist/modules/Order/utils.js +65 -104
  18. package/dist/modules/Payment/types.d.ts +1 -21
  19. package/dist/modules/Payment/types.js +0 -2
  20. package/dist/modules/Payment/walletpass.d.ts +1 -1
  21. package/dist/modules/Payment/walletpass.js +47 -80
  22. package/dist/modules/Rules/index.d.ts +2 -2
  23. package/dist/modules/Rules/index.js +190 -482
  24. package/dist/modules/Rules/types.d.ts +2 -4
  25. package/dist/server/modules/order/types.d.ts +0 -2
  26. package/dist/server/utils/small-ticket.js +1 -1
  27. package/dist/solution/BaseSales/index.d.ts +2 -3
  28. package/dist/solution/BaseSales/index.js +77 -44
  29. package/dist/solution/BaseSales/types.d.ts +7 -3
  30. package/dist/solution/BaseSales/utils/cartPromotion.js +126 -141
  31. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +40 -25
  32. package/dist/solution/BaseSales/utils.js +3 -2
  33. package/dist/solution/BookingByStep/index.d.ts +1 -1
  34. package/dist/solution/BookingTicket/index.d.ts +3 -2
  35. package/dist/solution/BookingTicket/index.js +63 -60
  36. package/dist/solution/BookingTicket/types.d.ts +1 -5
  37. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  38. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +147 -338
  39. package/dist/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  40. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  41. package/dist/solution/BookingTicket/utils/scan/formatGlobalScan.js +6 -19
  42. package/dist/solution/ScanOrder/utils.js +3 -2
  43. package/dist/solution/ShopDiscount/index.d.ts +0 -2
  44. package/dist/solution/ShopDiscount/index.js +42 -99
  45. package/dist/solution/ShopDiscount/utils.d.ts +2 -4
  46. package/dist/solution/ShopDiscount/utils.js +23 -43
  47. package/dist/solution/UnifiedBookingSales/index.js +2 -2
  48. package/lib/model/strategy/adapter/promotion/index.js +1 -46
  49. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -2
  50. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  51. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +6 -35
  52. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -13
  53. package/lib/modules/Customer/index.js +1 -5
  54. package/lib/modules/Customer/types.d.ts +0 -2
  55. package/lib/modules/Discount/index.d.ts +2 -2
  56. package/lib/modules/Discount/index.js +129 -23
  57. package/lib/modules/Discount/types.d.ts +5 -36
  58. package/lib/modules/Order/index.d.ts +2 -7
  59. package/lib/modules/Order/index.js +109 -222
  60. package/lib/modules/Order/utils/orderCollectionIdentity.js +11 -14
  61. package/lib/modules/Order/utils/weighedProduct.d.ts +12 -0
  62. package/lib/modules/Order/utils/weighedProduct.js +89 -0
  63. package/lib/modules/Order/utils.d.ts +1 -1
  64. package/lib/modules/Order/utils.js +6 -41
  65. package/lib/modules/Payment/types.d.ts +1 -21
  66. package/lib/modules/Payment/types.js +0 -1
  67. package/lib/modules/Payment/walletpass.d.ts +1 -1
  68. package/lib/modules/Payment/walletpass.js +9 -29
  69. package/lib/modules/Rules/index.d.ts +2 -2
  70. package/lib/modules/Rules/index.js +114 -359
  71. package/lib/modules/Rules/types.d.ts +2 -4
  72. package/lib/server/modules/order/types.d.ts +0 -2
  73. package/lib/server/utils/small-ticket.js +1 -1
  74. package/lib/solution/BaseSales/index.d.ts +2 -3
  75. package/lib/solution/BaseSales/index.js +17 -11
  76. package/lib/solution/BaseSales/types.d.ts +7 -3
  77. package/lib/solution/BaseSales/utils/cartPromotion.js +4 -12
  78. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +24 -9
  79. package/lib/solution/BaseSales/utils.js +2 -1
  80. package/lib/solution/BookingByStep/index.d.ts +1 -1
  81. package/lib/solution/BookingTicket/index.d.ts +3 -2
  82. package/lib/solution/BookingTicket/index.js +33 -36
  83. package/lib/solution/BookingTicket/types.d.ts +1 -5
  84. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +0 -2
  85. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +42 -174
  86. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +4 -8
  87. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.d.ts +0 -6
  88. package/lib/solution/BookingTicket/utils/scan/formatGlobalScan.js +3 -11
  89. package/lib/solution/ScanOrder/utils.js +2 -1
  90. package/lib/solution/ShopDiscount/index.d.ts +0 -2
  91. package/lib/solution/ShopDiscount/index.js +9 -55
  92. package/lib/solution/ShopDiscount/utils.d.ts +2 -4
  93. package/lib/solution/ShopDiscount/utils.js +25 -42
  94. package/lib/solution/UnifiedBookingSales/index.js +2 -2
  95. package/package.json +1 -1
  96. package/dist/modules/Discount/availability.d.ts +0 -7
  97. package/dist/modules/Discount/availability.js +0 -49
  98. package/dist/modules/Discount/entitlementPass.d.ts +0 -34
  99. package/dist/modules/Discount/entitlementPass.js +0 -147
  100. package/lib/modules/Discount/availability.d.ts +0 -7
  101. package/lib/modules/Discount/availability.js +0 -43
  102. package/lib/modules/Discount/entitlementPass.d.ts +0 -34
  103. package/lib/modules/Discount/entitlementPass.js +0 -141
@@ -5,21 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.applyGlobalScan = applyGlobalScan;
7
7
  var _addProductDecision = require("../addProductDecision");
8
+ var _cartView = require("../cartView");
8
9
  var _scanProductValues = require("./scanProductValues");
9
10
  /** applyGlobalScan 所需的 BookingTicket 运行时能力 */
10
11
 
11
- function getRealCustomerId(customer) {
12
- const customerId = Number(customer?.id ?? customer?.customer_id);
13
- return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
14
- }
15
- function getWalletAssetCustomerId(asset) {
16
- const customerId = Number(asset?.customer_id ?? asset?.holder?.customer_id);
17
- return Number.isInteger(customerId) && customerId > 1 ? customerId : undefined;
18
- }
19
- function getErrorMessage(error) {
20
- return error instanceof Error ? error.message : String(error || '');
21
- }
22
-
23
12
  /**
24
13
  * 处理单条扫码商品的加车决策(含弹窗链)。
25
14
  */
@@ -104,81 +93,17 @@ async function applyGlobalScan(host, formatted, bridge) {
104
93
  const {
105
94
  searchType,
106
95
  data,
107
- scanCode,
108
- customerId: formattedCustomerId,
109
- isCrossShopWallet,
110
- isWalletPassUnavailableAtStore
96
+ scanCode
111
97
  } = formatted;
112
98
  if (searchType === 'wallet') {
113
- const currentCustomer = host.getOrderCustomerSnapshot();
114
- const currentCustomerId = getRealCustomerId(currentCustomer);
115
- let customer = data;
116
- if (isCrossShopWallet) {
117
- const sourceCustomerId = getRealCustomerId({
118
- id: formattedCustomerId
119
- });
120
- if (sourceCustomerId === undefined || !host.resolveCustomerById) {
121
- bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
122
- return {
123
- status: 'failed',
124
- reason: 'invalid_data'
125
- };
126
- }
127
- try {
128
- customer = await host.resolveCustomerById(sourceCustomerId);
129
- } catch (error) {
130
- bridge?.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
131
- return {
132
- status: 'failed',
133
- reason: 'invalid_data'
134
- };
135
- }
136
- }
137
- const customerId = getRealCustomerId(customer) ?? (!isCrossShopWallet ? getRealCustomerId({
138
- id: formattedCustomerId
139
- }) : undefined);
140
- if (!customer || customerId === undefined) {
99
+ if (!data) {
141
100
  bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
142
101
  return {
143
102
  status: 'failed',
144
103
  reason: 'invalid_data'
145
104
  };
146
105
  }
147
- const orderCustomer = customer.id === undefined || customer.id === null ? {
148
- ...customer,
149
- id: customerId
150
- } : customer;
151
- if (currentCustomerId === customerId) {
152
- return {
153
- status: 'success',
154
- kind: 'customer'
155
- };
156
- }
157
- if (currentCustomerId !== undefined) {
158
- // 未接入新桥接的宿主保持原行为:已有客户时不直接覆盖。
159
- if (!bridge?.requestCustomerSwitch) {
160
- return {
161
- status: 'success',
162
- kind: 'customer'
163
- };
164
- }
165
- try {
166
- const switched = await bridge.requestCustomerSwitch(orderCustomer);
167
- return switched ? {
168
- status: 'success',
169
- kind: 'customer'
170
- } : {
171
- status: 'cancelled'
172
- };
173
- } catch (error) {
174
- bridge.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
175
- return {
176
- status: 'failed',
177
- reason: 'invalid_data'
178
- };
179
- }
180
- }
181
- host.setOrderCustomer(orderCustomer);
106
+ host.setOrderCustomer(data);
182
107
  bridge?.onNotify?.('success', 'pisell2.text.add-client-success');
183
108
  return {
184
109
  status: 'success',
@@ -186,70 +111,8 @@ async function applyGlobalScan(host, formatted, bridge) {
186
111
  };
187
112
  }
188
113
  if (searchType === 'walletPass') {
189
- if (isWalletPassUnavailableAtStore) {
190
- bridge?.onNotify?.('fail', 'pisell2.text.wallet-pass-not-available-at-store');
191
- return {
192
- status: 'failed',
193
- reason: 'invalid_data'
194
- };
195
- }
196
114
  const snapshot = host.getOrderCustomerSnapshot();
197
- let activeCustomer = snapshot;
198
- const bindWalletPassCustomer = async asset => {
199
- if (getRealCustomerId(activeCustomer) !== undefined) {
200
- return {
201
- resolveFailed: false,
202
- customerBound: false
203
- };
204
- }
205
- const assetCustomerId = getWalletAssetCustomerId(asset) ?? getRealCustomerId({
206
- id: formattedCustomerId
207
- });
208
- let customer = null;
209
- if (assetCustomerId !== undefined) {
210
- if (!host.resolveCustomerById) {
211
- bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
212
- return {
213
- resolveFailed: true,
214
- customerBound: false
215
- };
216
- }
217
- try {
218
- customer = await host.resolveCustomerById(assetCustomerId);
219
- } catch (error) {
220
- console.warn('[GlobalScan] Wallet asset customer lookup failed', error);
221
- bridge?.onNotify?.('fail', getErrorMessage(error) || 'pisell2.text.scan-global-failed');
222
- return {
223
- resolveFailed: true,
224
- customerBound: false
225
- };
226
- }
227
- }
228
- const customerId = getRealCustomerId(customer);
229
- if (!customer || customerId === undefined) {
230
- if (assetCustomerId !== undefined) {
231
- bridge?.onNotify?.('fail', 'pisell2.text.scan-global-failed');
232
- }
233
- return {
234
- resolveFailed: assetCustomerId !== undefined,
235
- customerBound: false
236
- };
237
- }
238
- const orderCustomer = customer.id === undefined || customer.id === null ? {
239
- ...customer,
240
- id: customerId
241
- } : customer;
242
- host.setOrderCustomer(orderCustomer);
243
- activeCustomer = orderCustomer;
244
- await host.refreshWalletAssets?.({
245
- preserveSelection: false,
246
- retainSearchResultCodes: [scanCode]
247
- });
248
- return {
249
- resolveFailed: false,
250
- customerBound: true
251
- };
252
- };
115
+ const scannedCustomerIsWalkIn = (0, _cartView.isWalkInCustomer)(data);
253
116
  const trySelectWalletAsset = async () => {
254
117
  if (!host.scanWalletAsset) return null;
255
118
  const walletResult = await host.scanWalletAsset(scanCode).catch(error => {
@@ -260,56 +123,61 @@ async function applyGlobalScan(host, formatted, bridge) {
260
123
  if (walletResult.type !== 'normalCode' || !walletResult.asset) {
261
124
  return null;
262
125
  }
263
- const bindResult = await bindWalletPassCustomer(walletResult.asset);
264
126
  if (walletResult.selected) {
265
- if (!bindResult.resolveFailed) {
266
- bridge?.onNotify?.('success');
267
- }
127
+ bridge?.onNotify?.('success');
268
128
  return {
269
129
  status: 'success',
270
130
  kind: 'promotion'
271
131
  };
272
132
  }
273
133
  // 已识别为 Wallet 支付资产但当前不可用:保留禁用展示,不回退优惠码。
274
- if (!bindResult.resolveFailed) {
275
- bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
276
- }
134
+ bridge?.onNotify?.('fail', 'pisell2.text.goodpass.code-invalid-cart');
277
135
  return {
278
136
  status: 'failed',
279
137
  reason: 'invalid_data'
280
138
  };
281
139
  };
282
-
283
- // batch-search 可能返回来源门店客户;先映射到当前门店,确保 Wallet
284
- // 支付资产查询使用本店客户上下文。
285
- const bindResult = await bindWalletPassCustomer();
286
- const walletSelection = await trySelectWalletAsset();
287
- if (walletSelection) return walletSelection;
288
- if (!bridge?.applyPromotionCode) {
140
+ if ((0, _cartView.isWalkInCustomer)(snapshot) || scannedCustomerIsWalkIn) {
141
+ // 当前购物车或 walletPass 绑定客户为 walk-in 时不绑客户,避免覆盖已有下单客户。
142
+ const walletSelection = await trySelectWalletAsset();
143
+ if (walletSelection) return walletSelection;
144
+ if (!bridge?.applyPromotionCode) {
145
+ return {
146
+ status: 'failed',
147
+ reason: 'no_bridge'
148
+ };
149
+ }
150
+ const result = await bridge.applyPromotionCode(scanCode);
151
+ if (result?.isAccepted ?? result?.isAvailable) {
152
+ return {
153
+ status: 'success',
154
+ kind: 'promotion'
155
+ };
156
+ }
289
157
  return {
290
158
  status: 'failed',
291
- reason: 'no_bridge'
292
- };
293
- }
294
- const promotionCustomerId = getRealCustomerId(activeCustomer);
295
- const promotionResult = bindResult.customerBound ? await bridge.applyPromotionCode(scanCode, promotionCustomerId, {
296
- suppressFailureNotification: true
297
- }) : await bridge.applyPromotionCode(scanCode, promotionCustomerId);
298
- if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
299
- return {
300
- status: 'success',
301
- kind: 'promotion'
159
+ reason: 'invalid_data'
302
160
  };
303
161
  }
304
- if (bindResult.customerBound) {
305
- return {
306
- status: 'success',
307
- kind: 'customer'
308
- };
162
+ host.setOrderCustomer(data);
163
+ await host.refreshWalletAssets?.({
164
+ preserveSelection: false
165
+ });
166
+ const walletSelection = await trySelectWalletAsset();
167
+ if (walletSelection) return walletSelection;
168
+ if (bridge?.applyPromotionCode) {
169
+ const promotionResult = await bridge.applyPromotionCode(scanCode, Number(data?.id ?? data?.customer_id) || undefined);
170
+ if (promotionResult?.isAccepted ?? promotionResult?.isAvailable) {
171
+ return {
172
+ status: 'success',
173
+ kind: 'promotion'
174
+ };
175
+ }
309
176
  }
177
+ bridge?.onNotify?.('success', 'pisell2.text.add-client-success');
310
178
  return {
311
- status: 'failed',
312
- reason: 'invalid_data'
179
+ status: 'success',
180
+ kind: 'customer'
313
181
  };
314
182
  }
315
183
  if (searchType === 'product' || searchType === 'local_product') {
@@ -14,8 +14,7 @@ const searchWalletPass = async (request, code) => {
14
14
  // 翻译识别码名称 0:不翻译 1:翻译
15
15
  relation_product: 1,
16
16
  // 组装关联商品: 0不处理 1处理
17
- with_franchisor_data: 1,
18
- with: ['customer', 'franchiseeWalletPass:shop_id,source_shop_id,product_id,use'],
17
+ with: ['customer'],
19
18
  tags: ['point_card',
20
19
  // 积分卡
21
20
  'gift_card',
@@ -26,8 +25,6 @@ const searchWalletPass = async (request, code) => {
26
25
  // 折扣卡
27
26
  'good_pass',
28
27
  // 商品券
29
- 'entitlement_pass',
30
- // 月卡 / 年卡 / 多次使用卡
31
28
  'session_ticket',
32
29
  // 场次票
33
30
  'appointment_ticket' // 预约类门票
@@ -54,18 +51,17 @@ exports.searchWalletPass = searchWalletPass;
54
51
  const searchWallet = async (request, code) => {
55
52
  const params = {
56
53
  code,
57
- with_customer: 1,
58
- with_franchisor_data: 1
54
+ with_customer: 1
59
55
  };
60
56
  try {
61
57
  const res = await request?.post('/wallet/detail/search', params);
62
- if (res?.status === true && res?.code === 200 && !!res?.data) {
58
+ if (res?.code == 200 && !!res?.data) {
63
59
  return {
64
60
  searchType: 'wallet',
65
61
  response: res
66
62
  };
67
63
  }
68
- throw new Error(res?.message || '没有找到对应的识别码');
64
+ throw new Error('没有找到对应的识别码');
69
65
  } catch (error) {
70
66
  throw error;
71
67
  }
@@ -6,12 +6,6 @@ export interface GlobalScanFormattedResult {
6
6
  searchType: GlobalScanSearchType;
7
7
  data: any;
8
8
  scanCode: string;
9
- /** Wallet / Wallet Pass 来源客户 ID;跨店时必须先解析为当前店客户。 */
10
- customerId?: string | number;
11
- /** 仅 Wallet 返回;true 时禁止直接使用响应内的来源客户。 */
12
- isCrossShopWallet?: boolean;
13
- /** 总店 Wallet Pass 未共享给当前子店。 */
14
- isWalletPassUnavailableAtStore?: boolean;
15
9
  }
16
10
  interface RawScanSearchResult {
17
11
  searchType?: GlobalScanSearchType;
@@ -36,22 +36,14 @@ function formatGlobalScanResult(raw, scanCode) {
36
36
  return {
37
37
  searchType,
38
38
  data: resultData?.customer,
39
- scanCode,
40
- customerId: resultData?.customer_id,
41
- isCrossShopWallet: resultData?.is_cross_shop_wallet === true || Number(resultData?.is_cross_shop_wallet) === 1
39
+ scanCode
42
40
  };
43
41
  }
44
42
  if (searchType === 'walletPass') {
45
- const firstResult = resultData?.[0];
46
- const isWalletPassUnavailableAtStore = firstResult?.is_franchisor_pass === 1 && firstResult?.franchisee_wallet_pass?.use !== 'enabled';
47
43
  return {
48
44
  searchType,
49
- data: firstResult?.customer,
50
- scanCode,
51
- customerId: firstResult?.customer_id ?? firstResult?.holder?.customer_id ?? firstResult?.customer?.id ?? firstResult?.customer?.customer_id,
52
- ...(isWalletPassUnavailableAtStore ? {
53
- isWalletPassUnavailableAtStore: true
54
- } : {})
45
+ data: resultData?.[0]?.customer,
46
+ scanCode
55
47
  };
56
48
  }
57
49
  if (searchType === 'product' || searchType === 'local_product') {
@@ -34,6 +34,7 @@ exports.toNonNegativeInt = toNonNegativeInt;
34
34
  exports.toNonNegativeNumber = toNonNegativeNumber;
35
35
  exports.toPositiveString = toPositiveString;
36
36
  exports.toPriceString = toPriceString;
37
+ var _weighedProduct = require("../../modules/Order/utils/weighedProduct");
37
38
  var _dayjs = _interopRequireDefault(require("dayjs"));
38
39
  var _decimal = _interopRequireDefault(require("decimal.js"));
39
40
  var _utils = require("../../modules/Order/utils");
@@ -612,7 +613,7 @@ function normalizeOrderProduct(product) {
612
613
  });
613
614
  const composedOriginalPrice = (0, _utils.composeLinePrice)({
614
615
  mainPrice: mainOriginalStr,
615
- bundle: normalizedBundle,
616
+ bundle: Number(productSku.open_sold_weight) === 1 && (0, _manualProductDiscount.hasManualProductDiscountFlag)(metadata) ? (0, _weighedProduct.withOriginalBundleOptionPrices)(normalizedBundle) : normalizedBundle,
616
617
  useOriginalBundle: true
617
618
  });
618
619
  const finalOriginalPrice = (0, _utils.resolveManualOverrideLineOriginalPrice)({
@@ -43,7 +43,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
43
43
  batchSearchByProductIds(productIds: number[]): Promise<Discount[]>;
44
44
  scanCode(code: string, customerId?: number): Promise<{
45
45
  isAvailable: boolean;
46
- isAccepted?: boolean;
47
46
  productList: Record<string, any>[];
48
47
  discountList: Discount[];
49
48
  type: "server" | "clientCalc";
@@ -63,7 +62,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
63
62
  action?: 'create' | 'edit';
64
63
  with_good_pass?: 0 | 1;
65
64
  with_discount_card?: 0 | 1;
66
- with_entitlement_pass?: 0 | 1;
67
65
  }): Promise<void>;
68
66
  }
69
67
  export default ShopDiscountImpl;
@@ -7,10 +7,8 @@ exports.default = exports.ShopDiscountImpl = void 0;
7
7
  var _BaseModule = require("../../modules/BaseModule");
8
8
  var _Discount = require("../../modules/Discount");
9
9
  var _Rules = require("../../modules/Rules");
10
- var _entitlementPass = require("../../modules/Discount/entitlementPass");
11
10
  var _utils = require("./utils");
12
11
  var _types = require("../../modules/Rules/types");
13
- var _availability = require("../../modules/Discount/availability");
14
12
  var _decimal = _interopRequireDefault(require("decimal.js"));
15
13
  var _lodashEs = require("lodash-es");
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -127,8 +125,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
127
125
  customerId: customer.id,
128
126
  action: 'create',
129
127
  with_good_pass: 1,
130
- with_discount_card: 1,
131
- with_entitlement_pass: 1
128
+ with_discount_card: 1
132
129
  });
133
130
  });
134
131
  }
@@ -350,7 +347,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
350
347
  const {
351
348
  productList: newProductList,
352
349
  discountList: newDiscountList,
353
- evaluatedDiscountList,
354
350
  isAvailable,
355
351
  unavailableReason
356
352
  } = rulesModule.isDiscountListAvailable({
@@ -365,7 +361,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
365
361
  productList: this.store.productList || [],
366
362
  discountList: this.getDiscountList()
367
363
  };
368
- let isAccepted = isAvailable;
369
364
  if (isAvailable) {
370
365
  this.setDiscountList(newDiscountList || []);
371
366
  this.store.originalDiscountList = newDiscountList || [];
@@ -373,34 +368,12 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
373
368
  if (this.isWalkIn() && resultDiscountList.length && this.options.otherParams?.platform === 'shop' && !((resultDiscountList[0].customer_id || 1) === 1)) {
374
369
  await this.getCustomerWallet(resultDiscountList[0].customer_id);
375
370
  }
376
- } else {
377
- const scannedIds = new Set(withScanList.map(discount => String(discount.id)));
378
- const retainedScannedDiscounts = (evaluatedDiscountList || withScanList).filter(discount => scannedIds.has(String(discount.id)) && !(0, _availability.getDiscountLifecycleReason)(discount));
379
- if (retainedScannedDiscounts.length) {
380
- const retainedDiscounts = new Map(this.getDiscountList().map(discount => [String(discount.id), discount]));
381
- retainedScannedDiscounts.forEach(discount => {
382
- retainedDiscounts.set(String(discount.id), {
383
- ...discount,
384
- isScan: true,
385
- isAvailable: false,
386
- isSelected: false,
387
- reasonCode: discount.reasonCode || 'product_not_applicable',
388
- appliedProductDetails: [],
389
- savedAmount: 0
390
- });
391
- });
392
- this.setDiscountList([...retainedDiscounts.values()]);
393
- this.store.originalDiscountList = this.getDiscountList();
394
- await this.store.discount?.setOriginalDiscountList(this.getDiscountList());
395
- isAccepted = true;
396
- }
397
371
  }
398
372
  return {
399
373
  type: "clientCalc",
400
374
  isAvailable: isAvailable || false,
401
- isAccepted: Boolean(isAccepted),
402
375
  productList: newProductList || this.store.productList || [],
403
- discountList: this.getDiscountList(),
376
+ discountList: newDiscountList || this.getDiscountList(),
404
377
  unavailableReason
405
378
  };
406
379
  } catch (error) {
@@ -443,7 +416,7 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
443
416
  if (item.booking_id) {
444
417
  const product = this.hooks?.getProduct(item);
445
418
  (item.discount_list || []).forEach(discount => {
446
- if (discount.id && ['entitlement_pass', 'good_pass', 'discount_card'].includes(discount.type)) {
419
+ if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
447
420
  const index = editModeDiscountList.findIndex(n => n.id === (discount.discount?.resource_id || discount.id));
448
421
  if (index !== -1) {
449
422
  editModeDiscountList[index] = {
@@ -549,8 +522,6 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
549
522
  with_good_pass: 1,
550
523
  with_discount_card: 1,
551
524
  with_wallet_pass_holder: 1,
552
- with_entitlement_pass: 1,
553
- filter_order_wallet_pass_usage: 0,
554
525
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
555
526
  ...(orderId ? {
556
527
  order_id: orderId
@@ -559,34 +530,17 @@ class ShopDiscountImpl extends _BaseModule.BaseModule {
559
530
  const goodPassList = prepareConfigResult?.discountList || [];
560
531
  const scanDiscount = this.getDiscountList()?.filter(item => item.isScan);
561
532
 
562
- // 扫码 Entitlement Pass 与客户列表重复时保留扫码选择状态,但刷新实时余额。
563
- // 其他券继续沿用原来的“保留扫码结果、剔除列表重复项”行为。
564
- const scanDiscountById = new Map(scanDiscount.map(discount => [String(discount.id), discount]));
565
- const refreshedScanEntitlementIds = new Set();
566
- const newGoodPassList = goodPassList.flatMap(discount => {
567
- const key = String(discount.id);
568
- const scannedDiscount = scanDiscountById.get(key);
569
- if (!scannedDiscount) return [discount];
570
- if ((0, _entitlementPass.isEntitlementPass)(scannedDiscount) && (0, _entitlementPass.isEntitlementPass)(discount)) {
571
- refreshedScanEntitlementIds.add(key);
572
- return [{
573
- ...discount,
574
- isScan: true,
575
- isSelected: scannedDiscount.isSelected ?? discount.isSelected,
576
- isManualSelect: scannedDiscount.isManualSelect ?? discount.isManualSelect
577
- }];
578
- }
579
- return [];
580
- });
581
- const retainedScanDiscounts = scanDiscount.filter(discount => !refreshedScanEntitlementIds.has(String(discount.id)));
582
- const newDiscountList = [...retainedScanDiscounts, ...newGoodPassList];
533
+ // goodPassList 里可能有 scanDiscount 重合的部分,goodPassList 需要剔除
534
+ const scanDiscountIds = scanDiscount.map(n => n.id);
535
+ const newGoodPassList = goodPassList?.filter(n => !scanDiscountIds.includes(n.id));
536
+ const newDiscountList = [...scanDiscount, ...(newGoodPassList || [])];
583
537
 
584
538
  // 存储原始优惠券列表
585
539
  this.store.originalDiscountList = newDiscountList;
586
540
  await this.store.discount?.setOriginalDiscountList(newDiscountList);
587
541
 
588
- // 日程限制交给 Rules 计算可用状态,展示列表保留当前不可用的卡券。
589
- const filteredDiscountList = newDiscountList;
542
+ // 根据当前预约时间过滤优惠券列表
543
+ const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
590
544
  this.store.filteredDiscountList = filteredDiscountList;
591
545
  this.setDiscountList(filteredDiscountList || []);
592
546
  if (this.store.productList?.length) {
@@ -59,14 +59,12 @@ export interface ScheduleItem {
59
59
  }
60
60
  export declare const getDateIsInSchedule: (dateTime: string, scheduleList: ScheduleItem[]) => boolean;
61
61
  /**
62
- * 根据商品使用时间过滤优惠券列表(预约开始时间或普通商品的当前时间)
62
+ * 根据预约时间过滤优惠券列表
63
63
  * @param discountList 优惠券列表
64
- * @param bookingTime 使用时间 (格式: YYYY-MM-DD HH:mm:ss),未确定时不提前过滤
64
+ * @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
65
65
  * @returns 过滤后的优惠券列表
66
66
  */
67
67
  export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
68
- /** 与抵扣计算共用时间判断,区分未开始、有效期不匹配和日程限制。 */
69
- export declare const getDiscountTimeUnavailableReason: (discount: Discount, useTime: string) => 'not_started' | 'time_limit' | 'outside_schedule' | undefined;
70
68
  /**
71
69
  * 判断是否是订单级别的固定金额折扣卡
72
70
  * @param discount 折扣
@@ -3,15 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.getDiscountTimeUnavailableReason = exports.getDiscountListAmountTotal = exports.getDiscountListAmount = exports.getDiscountAmount = exports.getDateIsInSchedule = exports.filterDiscountListByBookingTime = exports.calculateOrderLevelDiscountAllocation = void 0;
6
+ exports.uniqueById = exports.isOrderLevelFixedAmountDiscount = exports.isNormalProductByDurationSchedule = exports.isAllNormalProduct = exports.getDiscountListAmountTotal = exports.getDiscountListAmount = exports.getDiscountAmount = exports.getDateIsInSchedule = exports.filterDiscountListByBookingTime = exports.calculateOrderLevelDiscountAllocation = void 0;
7
7
  var _decimal = _interopRequireDefault(require("decimal.js"));
8
8
  var _dayjs = _interopRequireDefault(require("dayjs"));
9
- var _isSameOrAfter = _interopRequireDefault(require("dayjs/plugin/isSameOrAfter"));
10
- var _isSameOrBefore = _interopRequireDefault(require("dayjs/plugin/isSameOrBefore"));
11
- var _entitlementPass = require("../../modules/Discount/entitlementPass");
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- _dayjs.default.extend(_isSameOrAfter.default);
14
- _dayjs.default.extend(_isSameOrBefore.default);
15
10
  const uniqueById = (arr, key = 'id') => {
16
11
  const seen = new Set();
17
12
  return arr.filter(item => !seen.has(item[key]) && seen.add(item[key]));
@@ -40,8 +35,8 @@ const isAllNormalProduct = items => {
40
35
  */
41
36
  exports.isAllNormalProduct = isAllNormalProduct;
42
37
  const getDiscountAmount = (discount, total, price) => {
43
- // 商品券和 Entitlement Pass 都是全额抵扣。
44
- if ((0, _entitlementPass.isFullCoveragePass)(discount)) {
38
+ // 商品券
39
+ if (discount.tag === 'good_pass') {
45
40
  return new _decimal.default(price).minus(new _decimal.default(price || 0)).toNumber();
46
41
  }
47
42
 
@@ -381,53 +376,41 @@ const isInWeeklyRepeatForDate = (targetDate, startDate, repeatRule) => {
381
376
  };
382
377
 
383
378
  /**
384
- * 根据商品使用时间过滤优惠券列表(预约开始时间或普通商品的当前时间)
379
+ * 根据预约时间过滤优惠券列表
385
380
  * @param discountList 优惠券列表
386
- * @param bookingTime 使用时间 (格式: YYYY-MM-DD HH:mm:ss),未确定时不提前过滤
381
+ * @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
387
382
  * @returns 过滤后的优惠券列表
388
383
  */
389
384
  const filterDiscountListByBookingTime = (discountList, bookingTime) => {
390
- if (!bookingTime) return discountList;
391
- return discountList.filter(discount => !getDiscountTimeUnavailableReason(discount, bookingTime));
392
- };
393
-
394
- /** 与抵扣计算共用时间判断,区分未开始、有效期不匹配和日程限制。 */
395
- exports.filterDiscountListByBookingTime = filterDiscountListByBookingTime;
396
- const getDiscountTimeUnavailableReason = (discount, useTime) => {
397
- const useTimeDayjs = (0, _dayjs.default)(useTime);
398
- if (!useTimeDayjs.isValid()) return 'time_limit';
399
- try {
385
+ if (!bookingTime) {
386
+ return discountList;
387
+ }
388
+ return discountList.filter(discount => {
400
389
  if (discount?.metadata?.validity_type === "custom_schedule_validity") {
401
- return getDateIsInSchedule(useTime, discount.custom_schedule_snapshot?.data || []) ? undefined : 'outside_schedule';
402
- }
403
- const isHasStart = !!discount.start_date && !!discount.start_time;
404
- const startDate = (0, _dayjs.default)(`${discount.start_date} ${discount.start_time}`);
405
-
406
- // 开始时刻包含在有效期内。
407
- if (isHasStart) {
408
- if (!startDate.isValid()) return 'time_limit';
409
- if (useTimeDayjs.isBefore(startDate)) return 'not_started';
390
+ return getDateIsInSchedule(bookingTime, discount.custom_schedule_snapshot?.data || []);
410
391
  }
411
-
412
- // 到期时刻不再可用;expire_time 为空时为长期有效。
413
- const expireTime = discount.expire_time ? (0, _dayjs.default)(discount.expire_time) : null;
414
- const isBeforeExpire = expireTime ? expireTime.isValid() && useTimeDayjs.isBefore(expireTime) : true;
415
- if (!isBeforeExpire) return 'time_limit';
416
- const validity = discount.extension_data?.find(field => field.field_key === 'valid_times')?.value;
417
- if (validity?.restrict_use_by_schedule === true && !getDateIsInSchedule(useTime, discount.custom_schedule_snapshot?.data || [])) {
418
- return 'outside_schedule';
392
+ try {
393
+ const isHasStart = !!discount.start_date && !!discount.start_time;
394
+ const startDate = (0, _dayjs.default)(`${discount.start_date} ${discount.start_time}`);
395
+ const bookingTimeDayjs = (0, _dayjs.default)(bookingTime);
396
+
397
+ // 判断预约时间是否在开始时间之后
398
+ const isAfterStart = isHasStart ? bookingTimeDayjs.isSameOrAfter(startDate) : true;
399
+
400
+ // 判断预约时间是否在过期时间之前(expire_time 为空时为长期有效)
401
+ const isBeforeExpire = discount.expire_time ? bookingTimeDayjs.isSameOrBefore((0, _dayjs.default)(discount.expire_time)) : true;
402
+ return isAfterStart && isBeforeExpire;
403
+ } catch (error) {
404
+ return true;
419
405
  }
420
- return undefined;
421
- } catch (error) {
422
- return 'time_limit';
423
- }
406
+ });
424
407
  };
425
408
  /**
426
409
  * 判断是否是订单级别的固定金额折扣卡
427
410
  * @param discount 折扣
428
411
  * @returns 是否是订单级别的固定金额折扣卡
429
412
  */
430
- exports.getDiscountTimeUnavailableReason = getDiscountTimeUnavailableReason;
413
+ exports.filterDiscountListByBookingTime = filterDiscountListByBookingTime;
431
414
  const isOrderLevelFixedAmountDiscount = discount => {
432
415
  return discount.tag === 'product_discount_card' && discount?.metadata?.discount_card_type === 'fixed_amount' && discount?.metadata?.discount_calculation_mode === 'order_level';
433
416
  };
@@ -159,7 +159,7 @@ function buildPlannerDiscountResult(params) {
159
159
  const productDiscounts = [...(Array.isArray(product.discount_list) ? product.discount_list : []), ...(Array.isArray(product.product_bundle) ? product.product_bundle.flatMap(bundle => bundle?.discount_list || []) : [])];
160
160
  productDiscounts.forEach(discount => {
161
161
  const type = discount.tag || discount.type;
162
- if (!['entitlement_pass', 'good_pass', 'discount_card', 'product_discount_card'].includes(type)) return;
162
+ if (!['good_pass', 'discount_card', 'product_discount_card'].includes(type)) return;
163
163
  const discountId = resolvePlannerDiscountId(discount);
164
164
  applications.push({
165
165
  discountId,
@@ -201,7 +201,7 @@ function isLocalOrderId(orderId) {
201
201
  }
202
202
  function isCustomerBoundDiscount(discount) {
203
203
  const type = discount?.type ?? discount?.tag;
204
- return type === 'entitlement_pass' || type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
204
+ return type === 'good_pass' || type === 'discount_card' || type === 'product_discount_card';
205
205
  }
206
206
  function filterCustomerBoundDiscounts(discountList) {
207
207
  if (!Array.isArray(discountList)) return [];