@pisell/pisellos 0.0.484 → 0.0.486

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.
@@ -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);
@@ -150,7 +150,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
150
150
  if (productList.every(function (item) {
151
151
  var _product$discount_lis;
152
152
  var product = _this2.hooks.getProduct(item);
153
- return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) || (newDiscountList[0].tag === 'good_pass' ? product.price == 0 : product.total == 0));
153
+ return product.booking_id && (((_product$discount_lis = product.discount_list) === null || _product$discount_lis === void 0 ? void 0 : _product$discount_lis.length) || product.total == 0);
154
154
  })) {
155
155
  return {
156
156
  isAvailable: false,
@@ -46,6 +46,18 @@ var import_decimal = __toESM(require("decimal.js"));
46
46
  var import_utils = require("../../Product/utils");
47
47
  var import_utils2 = require("../../../solution/ShopDiscount/utils");
48
48
  var import_utils3 = require("../../Summary/utils");
49
+ var toDiscountPayload = (discountItem) => {
50
+ var _a, _b;
51
+ return {
52
+ amount: discountItem.amount,
53
+ tag: discountItem.type,
54
+ par_value: (_a = discountItem.discount) == null ? void 0 : _a.percent,
55
+ config: discountItem.config,
56
+ metadata: {
57
+ discount_card_type: (_b = discountItem == null ? void 0 : discountItem.discount) == null ? void 0 : _b.discount_card_type
58
+ }
59
+ };
60
+ };
49
61
  var handleVariantProduct = (product) => {
50
62
  var _a;
51
63
  if (product == null ? void 0 : product.product_variant_id) {
@@ -192,18 +204,24 @@ var formatProductToCartItemOrigin = (params) => {
192
204
  var getProductTotalPrice = (params) => {
193
205
  const { product, bundle, options, discounts } = params;
194
206
  let price = Number(product.price);
207
+ const optionRows = (options == null ? void 0 : options.map((currentValue) => ({
208
+ unit: Number(currentValue.price ?? currentValue.add_price ?? 0),
209
+ num: Number(currentValue.num ?? currentValue.quantity ?? 1)
210
+ }))) ?? [];
195
211
  if (discounts == null ? void 0 : discounts.length) {
196
212
  discounts.forEach((currentValue) => {
197
213
  var _a;
198
- price = (0, import_utils2.getDiscountAmount)({
199
- amount: currentValue.amount,
200
- tag: currentValue.type,
201
- par_value: currentValue.discount.percent,
202
- config: currentValue.config,
203
- metadata: {
204
- discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
214
+ const payload = toDiscountPayload(currentValue);
215
+ price = (0, import_utils2.getDiscountAmount)(payload, price, price);
216
+ if (((_a = currentValue == null ? void 0 : currentValue.config) == null ? void 0 : _a.deductOptionPrice) && optionRows.length) {
217
+ for (let i = 0; i < optionRows.length; i++) {
218
+ const row = optionRows[i];
219
+ optionRows[i] = {
220
+ ...row,
221
+ unit: (0, import_utils2.getDiscountAmount)(payload, row.unit, row.unit)
222
+ };
205
223
  }
206
- }, price, price);
224
+ }
207
225
  });
208
226
  }
209
227
  if (bundle == null ? void 0 : bundle.length) {
@@ -211,10 +229,11 @@ var getProductTotalPrice = (params) => {
211
229
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
212
230
  }, price);
213
231
  }
214
- if (options == null ? void 0 : options.length) {
215
- price = options.reduce((accumulator, currentValue) => {
216
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
217
- }, price);
232
+ if (optionRows.length) {
233
+ price = optionRows.reduce(
234
+ (accumulator, row) => accumulator + row.unit * row.num,
235
+ price
236
+ );
218
237
  }
219
238
  return Math.max(0, price);
220
239
  };
@@ -97,7 +97,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
97
97
  if (productList.every((item) => {
98
98
  var _a;
99
99
  const product = this.hooks.getProduct(item);
100
- return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || (newDiscountList[0].tag === "good_pass" ? product.price == 0 : product.total == 0));
100
+ return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || product.total == 0);
101
101
  })) {
102
102
  return {
103
103
  isAvailable: false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.484",
4
+ "version": "0.0.486",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",