@pisell/pisellos 2.1.117 → 2.1.118

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 (98) 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 +499 -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 +26 -0
  17. package/dist/model/strategy/adapter/walletPass/type.d.ts +187 -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 +1104 -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 +56 -24
  29. package/dist/modules/Discount/types.d.ts +18 -0
  30. package/dist/modules/Payment/index.d.ts +2 -1
  31. package/dist/modules/Payment/index.js +10 -7
  32. package/dist/modules/Payment/utils.js +3 -0
  33. package/dist/modules/Payment/walletpass.d.ts +23 -0
  34. package/dist/modules/Payment/walletpass.js +191 -95
  35. package/dist/modules/Rules/index.d.ts +9 -5
  36. package/dist/modules/Rules/index.js +674 -162
  37. package/dist/modules/Rules/types.d.ts +2 -0
  38. package/dist/modules/Summary/types.d.ts +2 -0
  39. package/dist/modules/Summary/utils.d.ts +6 -0
  40. package/dist/modules/Summary/utils.js +21 -0
  41. package/dist/plugins/window.d.ts +2 -0
  42. package/dist/solution/BookingByStep/index.d.ts +1 -0
  43. package/dist/solution/BookingTicket/index.d.ts +1 -1
  44. package/dist/solution/Checkout/index.js +2 -0
  45. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  46. package/dist/solution/ShopDiscount/index.js +23 -7
  47. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  48. package/dist/solution/ShopDiscount/types.js +2 -1
  49. package/dist/solution/ShopDiscount/utils.js +26 -12
  50. package/lib/index.d.ts +1 -0
  51. package/lib/index.js +3 -1
  52. package/lib/model/index.d.ts +1 -0
  53. package/lib/model/index.js +23 -0
  54. package/lib/model/strategy/adapter/index.d.ts +3 -0
  55. package/lib/model/strategy/adapter/index.js +45 -0
  56. package/lib/model/strategy/adapter/type.d.ts +28 -0
  57. package/lib/model/strategy/adapter/type.js +17 -0
  58. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  59. package/lib/model/strategy/adapter/walletPass/evaluator.js +423 -0
  60. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  61. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  62. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  63. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  64. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  65. package/lib/model/strategy/adapter/walletPass/locales.js +54 -0
  66. package/lib/model/strategy/adapter/walletPass/type.d.ts +187 -0
  67. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  68. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  69. package/lib/model/strategy/adapter/walletPass/utils.js +791 -0
  70. package/lib/model/strategy/index.d.ts +94 -0
  71. package/lib/model/strategy/index.js +413 -0
  72. package/lib/model/strategy/strategy-example.d.ts +5 -0
  73. package/lib/model/strategy/strategy-example.js +318 -0
  74. package/lib/model/strategy/type.d.ts +228 -0
  75. package/lib/model/strategy/type.js +44 -0
  76. package/lib/modules/Cart/types.d.ts +2 -0
  77. package/lib/modules/Cart/utils/cartProduct.js +39 -11
  78. package/lib/modules/Discount/types.d.ts +18 -0
  79. package/lib/modules/Payment/index.d.ts +2 -1
  80. package/lib/modules/Payment/index.js +1 -0
  81. package/lib/modules/Payment/utils.js +3 -0
  82. package/lib/modules/Payment/walletpass.d.ts +23 -0
  83. package/lib/modules/Payment/walletpass.js +94 -17
  84. package/lib/modules/Rules/index.d.ts +9 -5
  85. package/lib/modules/Rules/index.js +779 -284
  86. package/lib/modules/Rules/types.d.ts +2 -0
  87. package/lib/modules/Summary/types.d.ts +2 -0
  88. package/lib/modules/Summary/utils.d.ts +6 -0
  89. package/lib/modules/Summary/utils.js +15 -0
  90. package/lib/plugins/window.d.ts +2 -0
  91. package/lib/solution/BookingByStep/index.d.ts +1 -0
  92. package/lib/solution/BookingTicket/index.d.ts +1 -1
  93. package/lib/solution/Checkout/index.js +2 -0
  94. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  95. package/lib/solution/ShopDiscount/index.js +22 -8
  96. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  97. package/lib/solution/ShopDiscount/utils.js +10 -6
  98. package/package.json +1 -1
@@ -15,6 +15,20 @@ import { isNormalProduct } from "../../Product/utils";
15
15
  import { getDiscountAmount } from "../../../solution/ShopDiscount/utils";
16
16
  import { calcDiscountListDifference } from "../../Summary/utils";
17
17
 
18
+ /** 与 Rules / ShopDiscount 一致的折扣入参,用于主价与 option 单价 */
19
+ var toDiscountPayload = function toDiscountPayload(discountItem) {
20
+ var _discountItem$discoun, _discountItem$discoun2;
21
+ return {
22
+ amount: discountItem.amount,
23
+ tag: discountItem.type,
24
+ par_value: (_discountItem$discoun = discountItem.discount) === null || _discountItem$discoun === void 0 ? void 0 : _discountItem$discoun.percent,
25
+ config: discountItem.config,
26
+ metadata: {
27
+ discount_card_type: discountItem === null || discountItem === void 0 || (_discountItem$discoun2 = discountItem.discount) === null || _discountItem$discoun2 === void 0 ? void 0 : _discountItem$discoun2.discount_card_type
28
+ }
29
+ };
30
+ };
31
+
18
32
  /**
19
33
  * @title 处理组合商品
20
34
  * @description 组合商品需要直接修改 product 里的价格和 is_charge_tax
@@ -58,6 +72,7 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
58
72
  quantity = _params$quantity === void 0 ? 1 : _params$quantity,
59
73
  discounts = params.discounts;
60
74
  var num = quantity; // 当前按照单个商品加入购物车
75
+
61
76
  if (product) {
62
77
  cartItem.id = product === null || product === void 0 ? void 0 : product.id;
63
78
  cartItem.name = product === null || product === void 0 ? void 0 : product.title;
@@ -83,6 +98,15 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
83
98
  num: num,
84
99
  discounts: discounts
85
100
  });
101
+ // 不包含折扣卡商品券的总价
102
+ var origin_total = getProductTotalPrice({
103
+ product: cartItem._productInit || cartItem._productOrigin,
104
+ bundle: bundle,
105
+ options: options,
106
+ num: num,
107
+ discounts: []
108
+ });
109
+ cartItem.summaryOriginTotal = (origin_total || 0) * (num || 1);
86
110
  cartItem.image = product === null || product === void 0 ? void 0 : product.cover;
87
111
  cartItem.like_status = 'common';
88
112
  cartItem.duration = product === null || product === void 0 ? void 0 : product.duration;
@@ -185,6 +209,7 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
185
209
  * @returns 商品总价
186
210
  */
187
211
  export var getProductTotalPrice = function getProductTotalPrice(params) {
212
+ var _options$map;
188
213
  var product = params.product,
189
214
  bundle = params.bundle,
190
215
  options = params.options,
@@ -192,22 +217,29 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
192
217
  // const num = params.num || 1;
193
218
  var price = Number(product.price);
194
219
 
220
+ // option 行:unit 折后价在循环中与主商品使用同一套 getDiscountAmount(含 deductOptionPrice)
221
+ var optionRows = (_options$map = options === null || options === void 0 ? void 0 : options.map(function (currentValue) {
222
+ var _ref, _currentValue$price, _ref2, _currentValue$num;
223
+ return {
224
+ unit: Number((_ref = (_currentValue$price = currentValue.price) !== null && _currentValue$price !== void 0 ? _currentValue$price : currentValue.add_price) !== null && _ref !== void 0 ? _ref : 0),
225
+ num: Number((_ref2 = (_currentValue$num = currentValue.num) !== null && _currentValue$num !== void 0 ? _currentValue$num : currentValue.quantity) !== null && _ref2 !== void 0 ? _ref2 : 1)
226
+ };
227
+ })) !== null && _options$map !== void 0 ? _options$map : [];
228
+
195
229
  // 如果商品有折扣,则计算折扣
196
230
  if (discounts !== null && discounts !== void 0 && discounts.length) {
197
231
  discounts.forEach(function (currentValue) {
198
- var _currentValue$discoun;
199
- // 不是商品券则代表折扣卡,计算打折后的价格
200
- // 一个商品折扣卡只能存在于一张
201
- // if (currentValue.type !== 'good_pass') {
202
- price = getDiscountAmount({
203
- amount: currentValue.amount,
204
- tag: currentValue.type,
205
- par_value: currentValue.discount.percent,
206
- metadata: {
207
- discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
232
+ var _currentValue$config;
233
+ var payload = toDiscountPayload(currentValue);
234
+ price = getDiscountAmount(payload, price, price);
235
+ if (currentValue !== null && currentValue !== void 0 && (_currentValue$config = currentValue.config) !== null && _currentValue$config !== void 0 && _currentValue$config.deductOptionPrice && optionRows.length) {
236
+ for (var i = 0; i < optionRows.length; i++) {
237
+ var row = optionRows[i];
238
+ optionRows[i] = _objectSpread(_objectSpread({}, row), {}, {
239
+ unit: getDiscountAmount(payload, row.unit, row.unit)
240
+ });
208
241
  }
209
- }, price, price);
210
- // }
242
+ }
211
243
  });
212
244
  }
213
245
  if (bundle !== null && bundle !== void 0 && bundle.length) {
@@ -216,10 +248,10 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
216
248
  }, price);
217
249
  }
218
250
 
219
- // 单规格
220
- if (options !== null && options !== void 0 && options.length) {
221
- price = options.reduce(function (accumulator, currentValue) {
222
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
251
+ // 单规格 / 加购 option
252
+ if (optionRows.length) {
253
+ price = optionRows.reduce(function (accumulator, row) {
254
+ return accumulator + row.unit * row.num;
223
255
  }, price);
224
256
  }
225
257
  return Math.max(0, price);
@@ -378,11 +410,11 @@ export var getProductDeposit = function getProductDeposit(params) {
378
410
  // 判定商品是否有定金规则
379
411
  if ((product === null || product === void 0 || (_product$custom_depos2 = product.custom_deposit_data) === null || _product$custom_depos2 === void 0 ? void 0 : _product$custom_depos2.has_deposit) == 1) {
380
412
  var total = new Decimal(0);
381
- var _ref = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
382
- deposit_fixed = _ref.deposit_fixed,
383
- deposit_percentage = _ref.deposit_percentage,
384
- deposit_policy_data = _ref.deposit_policy_data,
385
- self_deposit_policy_ids = _ref.self_deposit_policy_ids;
413
+ var _ref3 = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
414
+ deposit_fixed = _ref3.deposit_fixed,
415
+ deposit_percentage = _ref3.deposit_percentage,
416
+ deposit_policy_data = _ref3.deposit_policy_data,
417
+ self_deposit_policy_ids = _ref3.self_deposit_policy_ids;
386
418
  // 所有协议数据
387
419
  var allProtocols = deposit_policy_data || [];
388
420
  // 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
@@ -476,9 +508,9 @@ export var handleProductDeposit = function handleProductDeposit(params) {
476
508
  depositTotal: new Decimal(0)
477
509
  };
478
510
  }
479
- var _ref2 = depositData || {},
480
- deposit_fixed = _ref2.deposit_fixed,
481
- deposit_percentage = _ref2.deposit_percentage;
511
+ var _ref4 = depositData || {},
512
+ deposit_fixed = _ref4.deposit_fixed,
513
+ deposit_percentage = _ref4.deposit_percentage;
482
514
  if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
483
515
  var depositFixed = Decimal(deposit_fixed || 0);
484
516
  var depositPercent = Decimal(deposit_percentage || 0);
@@ -33,6 +33,8 @@ interface Limitedrelationproductdata {
33
33
  product_ids: number[];
34
34
  product_collection_id: number[];
35
35
  package_sub_item_usage_rules?: PackageSubItemUsageRules;
36
+ filter: 0 | 1;
37
+ exclude_product_ids: number[];
36
38
  }
37
39
  interface ApplicableProductDetails {
38
40
  amount: string;
@@ -89,6 +91,7 @@ export interface Discount {
89
91
  balance: string;
90
92
  format_title: Formattitle;
91
93
  metadata?: {
94
+ num?: number;
92
95
  discount_card_type?: 'fixed_amount' | 'percent';
93
96
  custom_product_bundle_map_id?: string;
94
97
  validity_type?: "custom_schedule_validity" | "fixed_validity";
@@ -113,6 +116,21 @@ export interface Discount {
113
116
  isSelected?: boolean;
114
117
  isAvailable?: boolean;
115
118
  isUsed?: boolean;
119
+ config?: {
120
+ isAvailable?: boolean;
121
+ /** 最大抵扣金额 */
122
+ maxDeductionAmount?: number;
123
+ /** 每单最多使用张数 */
124
+ maxUsagePerOrder?: number;
125
+ /** 是否抵扣税费与附加费 */
126
+ deductTaxAndFee?: boolean;
127
+ /** 适用粒度(多商品共用) */
128
+ allowCrossProduct?: boolean;
129
+ /** 可用商品数量上限 */
130
+ applicableProductLimit?: number;
131
+ /** 是否抵扣单规格价格 (Option Price) */
132
+ deductOptionPrice?: boolean;
133
+ };
116
134
  applicableProductIds?: number[];
117
135
  applicableProductDetails: ApplicableProductDetails[];
118
136
  appliedProductDetails: ApplicableProductDetails[];
@@ -1,5 +1,5 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
- import { RequestPlugin } from '../../plugins';
2
+ import { RequestPlugin, WindowPlugin } from '../../plugins';
3
3
  import { BaseModule } from '../BaseModule';
4
4
  import { PaymentModuleAPI, PaymentMethod, PaymentOrder, PaymentItem, PaymentItemInput, PaymentUpdateFields, PushOrderParams, CashPayment, EftposPayment, WalletPassPayment, RoundingRule, RoundingInterval, RoundingResult } from './types';
5
5
  export * from './types';
@@ -21,6 +21,7 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
21
21
  request: RequestPlugin;
22
22
  private app;
23
23
  private store;
24
+ window: WindowPlugin;
24
25
  private dbManager;
25
26
  private logger;
26
27
  protected otherParams: any;
@@ -81,6 +81,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
81
81
  _defineProperty(_assertThisInitialized(_this), "app", void 0);
82
82
  // App instance
83
83
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
84
+ _defineProperty(_assertThisInitialized(_this), "window", void 0);
85
+ // WindowPlugin 实例
84
86
  _defineProperty(_assertThisInitialized(_this), "dbManager", void 0);
85
87
  // IndexDBManager 实例
86
88
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
@@ -110,26 +112,27 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
110
112
  // 获取依赖的插件
111
113
  this.request = core.getPlugin('request');
112
114
  appPlugin = core.getPlugin('app');
115
+ this.window = core.getPlugin('window');
113
116
  if (this.request) {
114
- _context.next = 7;
117
+ _context.next = 8;
115
118
  break;
116
119
  }
117
120
  throw new Error('支付模块需要 request 插件支持');
118
- case 7:
121
+ case 8:
119
122
  if (appPlugin) {
120
- _context.next = 9;
123
+ _context.next = 10;
121
124
  break;
122
125
  }
123
126
  throw new Error('支付模块需要 app 插件支持');
124
- case 9:
127
+ case 10:
125
128
  this.app = appPlugin.getApp();
126
129
  this.dbManager = this.app.dbManager;
127
130
  this.logger = this.app.logger;
128
131
 
129
132
  // 确保支付模块所需的对象存储已创建
130
- _context.next = 14;
133
+ _context.next = 15;
131
134
  return this.ensurePaymentTables();
132
- case 14:
135
+ case 15:
133
136
  this.registerNetworkHandlers();
134
137
 
135
138
  // // 预连接数据库
@@ -137,7 +140,7 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
137
140
 
138
141
  console.log('[PaymentModule] 初始化完成');
139
142
  this.logInfo('PaymentModule initialized successfully');
140
- case 17:
143
+ case 18:
141
144
  case "end":
142
145
  return _context.stop();
143
146
  }
@@ -1,5 +1,8 @@
1
1
  // 获取walletPass可用最大金额
2
2
  export var getAvailableMaxAmount = function getAvailableMaxAmount(data) {
3
+ if (typeof data._available_max_amount === 'number') {
4
+ return data._available_max_amount;
5
+ }
3
6
  return data.tag !== 'point_card' ? data.available_max_amount : data === null || data === void 0 ? void 0 : data.recommended_usage_amount;
4
7
  };
5
8
 
@@ -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
  */