@pisell/pisellos 2.1.108 → 2.1.110

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.
@@ -20,7 +20,8 @@ var defaultStrategyMetadataCustom = {
20
20
  allowCrossProduct: true,
21
21
  applicableProductLimit: 0,
22
22
  deductTaxAndFee: true,
23
- maxPassesPerItem: 0
23
+ maxPassesPerItem: 0,
24
+ deductOptionPrice: false
24
25
  };
25
26
 
26
27
  /**
@@ -43,6 +43,8 @@ export interface Voucher {
43
43
  applicableProductLimit: number;
44
44
  /** 单订单行每单位可用同一 Wallet Pass 券次数;该行总券次上限 = maxPassesPerItem × 该行 quantity(按行唯一键区分)。0 表示不限制。 */
45
45
  maxPassesPerItem: number;
46
+ /** 是否抵扣单规格价格 (Option Price),默认 false。开启后折扣范围包含 option 的 add_price */
47
+ deductOptionPrice: boolean;
46
48
  };
47
49
  }
48
50
  /**
@@ -62,6 +64,13 @@ export interface Product {
62
64
  main_product_original_price?: number;
63
65
  /** 主商品折扣后金额,不包含套餐子商品 */
64
66
  main_product_selling_price?: number;
67
+ /** 单规格(Option)列表 */
68
+ product_options?: {
69
+ id: number;
70
+ add_price: number | string;
71
+ num: number;
72
+ [key: string]: any;
73
+ }[];
65
74
  /** 主商品税费 */
66
75
  tax_fee: number;
67
76
  metadata: {
@@ -138,6 +147,8 @@ export interface EvaluatorInput {
138
147
  applicableProductLimit: number;
139
148
  /** 单订单行每单位可用同一 Wallet Pass 券次数;行总上限 = maxPassesPerItem × 该行 quantity(按行唯一键计)。0 表示不限制。 */
140
149
  maxPassesPerItem: number;
150
+ /** 是否抵扣单规格价格 (Option Price),默认 false */
151
+ deductOptionPrice: boolean;
141
152
  }>[];
142
153
  }
143
154
  /**
@@ -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
@@ -195,6 +209,7 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
195
209
  * @returns 商品总价
196
210
  */
197
211
  export var getProductTotalPrice = function getProductTotalPrice(params) {
212
+ var _options$map;
198
213
  var product = params.product,
199
214
  bundle = params.bundle,
200
215
  options = params.options,
@@ -202,23 +217,29 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
202
217
  // const num = params.num || 1;
203
218
  var price = Number(product.price);
204
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
+
205
229
  // 如果商品有折扣,则计算折扣
206
230
  if (discounts !== null && discounts !== void 0 && discounts.length) {
207
231
  discounts.forEach(function (currentValue) {
208
- var _currentValue$discoun;
209
- // 不是商品券则代表折扣卡,计算打折后的价格
210
- // 一个商品折扣卡只能存在于一张
211
- // if (currentValue.type !== 'good_pass') {
212
- price = getDiscountAmount({
213
- amount: currentValue.amount,
214
- tag: currentValue.type,
215
- par_value: currentValue.discount.percent,
216
- config: currentValue.config,
217
- metadata: {
218
- 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
+ });
219
241
  }
220
- }, price, price);
221
- // }
242
+ }
222
243
  });
223
244
  }
224
245
  if (bundle !== null && bundle !== void 0 && bundle.length) {
@@ -227,10 +248,10 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
227
248
  }, price);
228
249
  }
229
250
 
230
- // 单规格
231
- if (options !== null && options !== void 0 && options.length) {
232
- price = options.reduce(function (accumulator, currentValue) {
233
- 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;
234
255
  }, price);
235
256
  }
236
257
  return Math.max(0, price);
@@ -389,11 +410,11 @@ export var getProductDeposit = function getProductDeposit(params) {
389
410
  // 判定商品是否有定金规则
390
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) {
391
412
  var total = new Decimal(0);
392
- var _ref = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
393
- deposit_fixed = _ref.deposit_fixed,
394
- deposit_percentage = _ref.deposit_percentage,
395
- deposit_policy_data = _ref.deposit_policy_data,
396
- 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;
397
418
  // 所有协议数据
398
419
  var allProtocols = deposit_policy_data || [];
399
420
  // 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
@@ -487,9 +508,9 @@ export var handleProductDeposit = function handleProductDeposit(params) {
487
508
  depositTotal: new Decimal(0)
488
509
  };
489
510
  }
490
- var _ref2 = depositData || {},
491
- deposit_fixed = _ref2.deposit_fixed,
492
- deposit_percentage = _ref2.deposit_percentage;
511
+ var _ref4 = depositData || {},
512
+ deposit_fixed = _ref4.deposit_fixed,
513
+ deposit_percentage = _ref4.deposit_percentage;
493
514
  if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
494
515
  var depositFixed = Decimal(deposit_fixed || 0);
495
516
  var depositPercent = Decimal(deposit_percentage || 0);
@@ -120,6 +120,8 @@ export interface Discount {
120
120
  allowCrossProduct?: boolean;
121
121
  /** 可用商品数量上限 */
122
122
  applicableProductLimit?: number;
123
+ /** 是否抵扣单规格价格 (Option Price) */
124
+ deductOptionPrice?: boolean;
123
125
  };
124
126
  applicableProductIds?: number[];
125
127
  applicableProductDetails: ApplicableProductDetails[];
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }