@pisell/pisellos 2.1.52 → 2.1.54

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 (101) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +3 -0
  6. package/dist/model/strategy/adapter/index.js +4 -0
  7. package/dist/model/strategy/adapter/type.d.ts +28 -0
  8. package/dist/model/strategy/adapter/type.js +1 -0
  9. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  10. package/dist/model/strategy/adapter/walletPass/evaluator.js +496 -0
  11. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  12. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  13. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  14. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  15. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  16. package/dist/model/strategy/adapter/walletPass/locales.js +23 -0
  17. package/dist/model/strategy/adapter/walletPass/type.d.ts +163 -0
  18. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  19. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  20. package/dist/model/strategy/adapter/walletPass/utils.js +965 -0
  21. package/dist/model/strategy/index.d.ts +94 -0
  22. package/dist/model/strategy/index.js +551 -0
  23. package/dist/model/strategy/strategy-example.d.ts +5 -0
  24. package/dist/model/strategy/strategy-example.js +331 -0
  25. package/dist/model/strategy/type.d.ts +228 -0
  26. package/dist/model/strategy/type.js +94 -0
  27. package/dist/modules/Cart/types.d.ts +2 -0
  28. package/dist/modules/Cart/utils/cartProduct.js +11 -0
  29. package/dist/modules/Discount/index.d.ts +1 -0
  30. package/dist/modules/Discount/index.js +1 -1
  31. package/dist/modules/Discount/types.d.ts +15 -0
  32. package/dist/modules/Payment/index.d.ts +2 -1
  33. package/dist/modules/Payment/index.js +10 -7
  34. package/dist/modules/Payment/utils.js +3 -0
  35. package/dist/modules/Payment/walletpass.d.ts +23 -0
  36. package/dist/modules/Payment/walletpass.js +191 -95
  37. package/dist/modules/Rules/index.d.ts +15 -3
  38. package/dist/modules/Rules/index.js +194 -28
  39. package/dist/modules/Rules/types.d.ts +5 -0
  40. package/dist/modules/Summary/types.d.ts +2 -0
  41. package/dist/modules/Summary/utils.d.ts +6 -0
  42. package/dist/modules/Summary/utils.js +21 -0
  43. package/dist/plugins/window.d.ts +2 -0
  44. package/dist/solution/BookingByStep/index.d.ts +1 -0
  45. package/dist/solution/BookingByStep/utils/capacity.js +1 -2
  46. package/dist/solution/Checkout/index.js +2 -0
  47. package/dist/solution/ShopDiscount/index.d.ts +4 -0
  48. package/dist/solution/ShopDiscount/index.js +26 -5
  49. package/dist/solution/ShopDiscount/types.d.ts +6 -0
  50. package/dist/solution/ShopDiscount/utils.js +26 -11
  51. package/lib/index.d.ts +1 -0
  52. package/lib/index.js +3 -1
  53. package/lib/model/index.d.ts +1 -0
  54. package/lib/model/index.js +23 -0
  55. package/lib/model/strategy/adapter/index.d.ts +3 -0
  56. package/lib/model/strategy/adapter/index.js +45 -0
  57. package/lib/model/strategy/adapter/type.d.ts +28 -0
  58. package/lib/model/strategy/adapter/type.js +17 -0
  59. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  60. package/lib/model/strategy/adapter/walletPass/evaluator.js +420 -0
  61. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  62. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  63. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  64. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  65. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  66. package/lib/model/strategy/adapter/walletPass/locales.js +51 -0
  67. package/lib/model/strategy/adapter/walletPass/type.d.ts +163 -0
  68. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  69. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  70. package/lib/model/strategy/adapter/walletPass/utils.js +660 -0
  71. package/lib/model/strategy/index.d.ts +94 -0
  72. package/lib/model/strategy/index.js +413 -0
  73. package/lib/model/strategy/strategy-example.d.ts +5 -0
  74. package/lib/model/strategy/strategy-example.js +318 -0
  75. package/lib/model/strategy/type.d.ts +228 -0
  76. package/lib/model/strategy/type.js +44 -0
  77. package/lib/modules/Cart/types.d.ts +2 -0
  78. package/lib/modules/Cart/utils/cartProduct.js +9 -0
  79. package/lib/modules/Discount/index.d.ts +1 -0
  80. package/lib/modules/Discount/index.js +1 -1
  81. package/lib/modules/Discount/types.d.ts +15 -0
  82. package/lib/modules/Payment/index.d.ts +2 -1
  83. package/lib/modules/Payment/index.js +1 -0
  84. package/lib/modules/Payment/utils.js +3 -0
  85. package/lib/modules/Payment/walletpass.d.ts +23 -0
  86. package/lib/modules/Payment/walletpass.js +94 -17
  87. package/lib/modules/Rules/index.d.ts +15 -3
  88. package/lib/modules/Rules/index.js +409 -195
  89. package/lib/modules/Rules/types.d.ts +5 -0
  90. package/lib/modules/Summary/types.d.ts +2 -0
  91. package/lib/modules/Summary/utils.d.ts +6 -0
  92. package/lib/modules/Summary/utils.js +15 -0
  93. package/lib/plugins/window.d.ts +2 -0
  94. package/lib/solution/BookingByStep/index.d.ts +1 -0
  95. package/lib/solution/BookingByStep/utils/capacity.js +1 -2
  96. package/lib/solution/Checkout/index.js +2 -0
  97. package/lib/solution/ShopDiscount/index.d.ts +4 -0
  98. package/lib/solution/ShopDiscount/index.js +18 -4
  99. package/lib/solution/ShopDiscount/types.d.ts +6 -0
  100. package/lib/solution/ShopDiscount/utils.js +10 -6
  101. package/package.json +1 -1
@@ -25,6 +25,9 @@ __export(utils_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(utils_exports);
27
27
  var getAvailableMaxAmount = (data) => {
28
+ if (typeof data._available_max_amount === "number") {
29
+ return data._available_max_amount;
30
+ }
28
31
  return data.tag !== "point_card" ? data.available_max_amount : data == null ? void 0 : data.recommended_usage_amount;
29
32
  };
30
33
  var formatWalletPassList2PreparePayments = (list) => {
@@ -9,6 +9,7 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
9
9
  private userIdentificationCodes;
10
10
  private searchResults;
11
11
  private walletParams;
12
+ private walletInitData;
12
13
  constructor(paymentModule: PaymentModule);
13
14
  /**
14
15
  * 发送事件的辅助方法
@@ -37,7 +38,14 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
37
38
  initializeWalletDataFromBusinessAsync(businessData: WalletInitBusinessData): Promise<{
38
39
  walletRecommendList: WalletRecommendItem[];
39
40
  userIdentificationCodes: UserIdentificationCodeItem[];
41
+ transformList: any[];
42
+ noApplicableVoucher: any[];
43
+ products: any[];
40
44
  }>;
45
+ /**
46
+ * 获取订单基础详情
47
+ */
48
+ getOrderBasicDetailAsync(orderId: string): Promise<any>;
41
49
  /**
42
50
  * 初始化钱包数据
43
51
  * 先获取推荐列表,再获取用户识别码列表(顺序执行)
@@ -45,6 +53,9 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
45
53
  initializeWalletDataAsync(baseParams: WalletDeductionRecommendParams): Promise<{
46
54
  walletRecommendList: WalletRecommendItem[];
47
55
  userIdentificationCodes: UserIdentificationCodeItem[];
56
+ transformList: any[];
57
+ noApplicableVoucher: any[];
58
+ products: any[];
48
59
  }>;
49
60
  getWalletPassRecommendListAsync(params: WalletDeductionRecommendParams): Promise<WalletRecommendItem[]>;
50
61
  formatWalletPassList2PreparePayments(list: WalletRecommendItem[]): {
@@ -92,6 +103,18 @@ export declare class WalletPassPaymentImpl implements WalletPassPayment {
92
103
  * 清除搜索结果缓存
93
104
  */
94
105
  clearSearchResults(): void;
106
+ /**
107
+ * 获取存储的钱包初始化数据
108
+ */
109
+ getStoredWalletInitData(): {
110
+ transformList: any[];
111
+ noApplicableVoucher: any[];
112
+ products: any[];
113
+ } | null;
114
+ /**
115
+ * 清除存储的钱包初始化数据
116
+ */
117
+ clearStoredWalletInitData(): void;
95
118
  /**
96
119
  * 清除所有缓存数据
97
120
  */
@@ -31,6 +31,7 @@ var WalletPassPaymentImpl = class {
31
31
  this.userIdentificationCodes = [];
32
32
  this.searchResults = [];
33
33
  this.walletParams = null;
34
+ this.walletInitData = null;
34
35
  }
35
36
  /**
36
37
  * 发送事件的辅助方法
@@ -42,7 +43,9 @@ var WalletPassPaymentImpl = class {
42
43
  const fullEventName = `${this.paymentModule.name}:${eventName}`;
43
44
  this.paymentModule.core.effects.emit(fullEventName, data);
44
45
  } catch (error) {
45
- this.paymentModule.logError("[WalletPass] 发送事件失败", error, { hook });
46
+ this.paymentModule.logError("[WalletPass] 发送事件失败", error, {
47
+ hook
48
+ });
46
49
  }
47
50
  }
48
51
  /**
@@ -112,7 +115,10 @@ var WalletPassPaymentImpl = class {
112
115
  if (Number(((_a = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _a.totalAmount) || 0) < 0 || Number(((_b = businessData == null ? void 0 : businessData.amountInfo) == null ? void 0 : _b.subTotal) || 0) < 0) {
113
116
  return {
114
117
  walletRecommendList: [],
115
- userIdentificationCodes: []
118
+ userIdentificationCodes: [],
119
+ transformList: [],
120
+ noApplicableVoucher: [],
121
+ products: []
116
122
  };
117
123
  }
118
124
  this.emitEvent(import_types.WalletPassHooks.OnWalletInitializationStarted, {
@@ -153,11 +159,28 @@ var WalletPassPaymentImpl = class {
153
159
  endTime,
154
160
  duration
155
161
  });
156
- this.paymentModule.logError(`[WalletPass] 从业务数据初始化钱包数据失败`, error, {
157
- duration: `${duration}ms`,
158
- customer_id: businessData.customer_id,
159
- totalAmount: (_h = businessData.amountInfo) == null ? void 0 : _h.totalAmount
160
- });
162
+ this.paymentModule.logError(
163
+ `[WalletPass] 从业务数据初始化钱包数据失败`,
164
+ error,
165
+ {
166
+ duration: `${duration}ms`,
167
+ customer_id: businessData.customer_id,
168
+ totalAmount: (_h = businessData.amountInfo) == null ? void 0 : _h.totalAmount
169
+ }
170
+ );
171
+ throw error;
172
+ }
173
+ }
174
+ /**
175
+ * 获取订单基础详情
176
+ */
177
+ async getOrderBasicDetailAsync(orderId) {
178
+ try {
179
+ const response = await this.paymentModule.request.get(
180
+ `/order/order/${orderId}/basic-detail`
181
+ );
182
+ return (response == null ? void 0 : response.data) || {};
183
+ } catch (error) {
161
184
  throw error;
162
185
  }
163
186
  }
@@ -166,19 +189,49 @@ var WalletPassPaymentImpl = class {
166
189
  * 先获取推荐列表,再获取用户识别码列表(顺序执行)
167
190
  */
168
191
  async initializeWalletDataAsync(baseParams) {
192
+ var _a, _b;
169
193
  try {
170
- const walletRecommendList = await this.getWalletPassRecommendListAsync(baseParams);
171
194
  const identificationParams = {
172
195
  ...baseParams,
173
196
  available: 2,
174
- prepare_payments: this.formatWalletPassList2PreparePayments(walletRecommendList),
197
+ prepare_payments: [],
175
198
  other_exact_codes: [],
176
199
  filter_prepare_wallet_pass: 1
177
200
  };
178
- const userIdentificationCodes = await this.getUserIdentificationCodeListAsync(identificationParams);
201
+ const [allList, orderBasicDetail] = await Promise.all([
202
+ this.getUserIdentificationCodeListAsync(identificationParams),
203
+ baseParams.payment_order_id ? this.getOrderBasicDetailAsync(baseParams.payment_order_id) : Promise.resolve(null)
204
+ ]);
205
+ const walletPassEvaluator = (_b = (_a = this.paymentModule.window) == null ? void 0 : _a.getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
206
+ if (!walletPassEvaluator) {
207
+ return {
208
+ walletRecommendList: [],
209
+ userIdentificationCodes: [],
210
+ transformList: [],
211
+ noApplicableVoucher: [],
212
+ products: []
213
+ };
214
+ }
215
+ const products = (orderBasicDetail == null ? void 0 : orderBasicDetail.detail) || baseParams.products;
216
+ const res = walletPassEvaluator == null ? void 0 : walletPassEvaluator.getRecommendedVouchers({
217
+ orderTotalAmount: baseParams.order_wait_pay_amount,
218
+ products,
219
+ vouchers: allList
220
+ });
221
+ const { recommended, transformList, noApplicableVoucher, recommendedAmount } = res;
222
+ console.log(res, "resres12");
223
+ this.walletRecommendList = recommended;
224
+ this.walletInitData = {
225
+ transformList,
226
+ noApplicableVoucher,
227
+ products: products || []
228
+ };
179
229
  return {
180
- walletRecommendList,
181
- userIdentificationCodes
230
+ walletRecommendList: recommended,
231
+ userIdentificationCodes: allList,
232
+ transformList,
233
+ noApplicableVoucher,
234
+ products: products || []
182
235
  };
183
236
  } catch (error) {
184
237
  this.paymentModule.logError("[WalletPass] 初始化钱包数据失败", error, {
@@ -261,10 +314,14 @@ var WalletPassPaymentImpl = class {
261
314
  });
262
315
  return this.userIdentificationCodes;
263
316
  } catch (error) {
264
- this.paymentModule.logError("[WalletPass] 获取用户识别码列表失败", error, {
265
- customer_id: params.customer_id,
266
- available: params.available
267
- });
317
+ this.paymentModule.logError(
318
+ "[WalletPass] 获取用户识别码列表失败",
319
+ error,
320
+ {
321
+ customer_id: params.customer_id,
322
+ available: params.available
323
+ }
324
+ );
268
325
  return [];
269
326
  }
270
327
  }
@@ -462,6 +519,19 @@ var WalletPassPaymentImpl = class {
462
519
  this.searchResults = [];
463
520
  this.paymentModule.logInfo("[WalletPass] 搜索结果缓存已清除");
464
521
  }
522
+ /**
523
+ * 获取存储的钱包初始化数据
524
+ */
525
+ getStoredWalletInitData() {
526
+ return this.walletInitData;
527
+ }
528
+ /**
529
+ * 清除存储的钱包初始化数据
530
+ */
531
+ clearStoredWalletInitData() {
532
+ this.walletInitData = null;
533
+ this.paymentModule.logInfo("[WalletPass] 钱包初始化数据已清除");
534
+ }
465
535
  /**
466
536
  * 清除所有缓存数据
467
537
  */
@@ -470,11 +540,18 @@ var WalletPassPaymentImpl = class {
470
540
  this.userIdentificationCodes = [];
471
541
  this.searchResults = [];
472
542
  this.walletParams = null;
543
+ this.walletInitData = null;
473
544
  this.emitEvent(import_types.WalletPassHooks.OnWalletCacheCleared, {
474
545
  clearedTypes: ["all"]
475
546
  });
476
547
  this.paymentModule.logInfo("[WalletPass] 所有缓存数据已清除", {
477
- cleared_types: ["walletRecommendList", "userIdentificationCodes", "searchResults", "walletParams"]
548
+ cleared_types: [
549
+ "walletRecommendList",
550
+ "userIdentificationCodes",
551
+ "searchResults",
552
+ "walletParams",
553
+ "walletInitData"
554
+ ]
478
555
  });
479
556
  }
480
557
  };
@@ -1,29 +1,41 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
3
  import { Rules, RulesModuleAPI, DiscountResult } from './types';
4
- import { Discount } from "../Discount/types";
4
+ import { Discount } from '../Discount/types';
5
5
  import { SetDiscountSelectedParams } from '../../solution/ShopDiscount/types';
6
+ import { WindowPlugin } from '../../plugins';
6
7
  export declare class RulesModule extends BaseModule implements Module, RulesModuleAPI {
7
8
  protected defaultName: string;
8
9
  protected defaultVersion: string;
9
10
  private store;
11
+ window: WindowPlugin;
10
12
  private hooks;
11
13
  constructor(name?: string, version?: string);
12
14
  initialize(core: PisellCore, options?: ModuleOptions): Promise<void>;
13
15
  setRulesList(rulesList: Rules[]): Promise<void>;
14
16
  getRulesList(): Rules[];
15
- isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, }: {
17
+ getWalletPassEvaluator(): import("../..").WalletPassEvaluator | undefined;
18
+ private checkHolderMatch;
19
+ isDiscountListAvailable({ oldDiscountList, newDiscountList, productList, holders, orderTotalAmount, }: {
16
20
  oldDiscountList: Discount[];
17
21
  newDiscountList: Discount[];
18
22
  productList: any[];
23
+ holders: {
24
+ form_record_id: number;
25
+ }[];
26
+ orderTotalAmount: number;
19
27
  }): {
20
28
  isAvailable: boolean;
21
29
  discountList: Discount[];
22
30
  productList: any[];
23
31
  };
24
- calcDiscount({ discountList, productList, }: {
32
+ calcDiscount({ discountList, productList, holders, orderTotalAmount }: {
25
33
  discountList: Discount[];
26
34
  productList: any[];
35
+ holders: {
36
+ form_record_id: number;
37
+ }[];
38
+ orderTotalAmount: number;
27
39
  }, options?: {
28
40
  isSelected?: boolean;
29
41
  discountId?: number;