@pisell/pisellos 2.0.16 → 2.0.17

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.
@@ -216,11 +216,6 @@ export declare const getProductDeposit: (params: {
216
216
  total: number;
217
217
  protocols: {
218
218
  id: number;
219
- /**
220
- * 格式化折扣到购物车
221
- * @param params 参数
222
- * @returns 格式化后的购物车
223
- */
224
219
  title: string;
225
220
  }[];
226
221
  } | null;
@@ -542,16 +542,18 @@ export var getProductDeposit = function getProductDeposit(params) {
542
542
 
543
543
  // 判定商品是否有定金规则
544
544
  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) {
545
- var protocols = [];
546
545
  var total = new Decimal(0);
547
546
  var _ref2 = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
548
547
  deposit_fixed = _ref2.deposit_fixed,
549
548
  deposit_percentage = _ref2.deposit_percentage,
550
- deposit_policy_data = _ref2.deposit_policy_data;
551
- // 协议数据
552
- protocols.push.apply(protocols, _toConsumableArray(deposit_policy_data || []));
549
+ deposit_policy_data = _ref2.deposit_policy_data,
550
+ self_deposit_policy_ids = _ref2.self_deposit_policy_ids;
551
+ // 所有协议数据
552
+ var allProtocols = deposit_policy_data || [];
553
553
  // 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
554
554
  var productHasDeposit = false;
555
+ // 关联的定金协议id
556
+ var protocolIds = [];
555
557
 
556
558
  // 判断主商品是否有定金规则
557
559
  if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
@@ -564,19 +566,22 @@ export var getProductDeposit = function getProductDeposit(params) {
564
566
  result = _handleProductDeposit.result;
565
567
  if (result) {
566
568
  total = depositTotal;
569
+ protocolIds.push.apply(protocolIds, _toConsumableArray(self_deposit_policy_ids || []));
567
570
  productHasDeposit = true;
568
571
  }
569
572
  } else {
570
573
  if (bundle !== null && bundle !== void 0 && bundle.length) {
571
- total = bundle.reduce(function (accumulator, currentBundleProduct) {
574
+ total = bundle.reduce(function (accumulator, currBundleProduct) {
575
+ var depositData = currBundleProduct === null || currBundleProduct === void 0 ? void 0 : currBundleProduct.custom_deposit_data;
572
576
  var _handleProductDeposit2 = handleProductDeposit({
573
- depositData: currentBundleProduct === null || currentBundleProduct === void 0 ? void 0 : currentBundleProduct.custom_deposit_data,
574
- total: currentBundleProduct.price,
575
- num: currentBundleProduct.num
577
+ depositData: depositData,
578
+ total: currBundleProduct === null || currBundleProduct === void 0 ? void 0 : currBundleProduct.price,
579
+ num: (currBundleProduct === null || currBundleProduct === void 0 ? void 0 : currBundleProduct.num) || 1
576
580
  }),
577
581
  depositTotal = _handleProductDeposit2.depositTotal,
578
582
  result = _handleProductDeposit2.result;
579
583
  if (result) {
584
+ protocolIds.push.apply(protocolIds, _toConsumableArray((depositData === null || depositData === void 0 ? void 0 : depositData.self_deposit_policy_ids) || []));
580
585
  productHasDeposit = true;
581
586
  return accumulator.plus(depositTotal);
582
587
  }
@@ -585,6 +590,10 @@ export var getProductDeposit = function getProductDeposit(params) {
585
590
  }
586
591
  }
587
592
  if (productHasDeposit) {
593
+ var ids = new Set(protocolIds);
594
+ var protocols = allProtocols.filter(function (item) {
595
+ return ids.has(item.id);
596
+ });
588
597
  return {
589
598
  total: total.toNumber(),
590
599
  protocols: protocols
@@ -168,6 +168,8 @@ export interface ProductData {
168
168
  deposit_fixed?: string;
169
169
  /** 定金百分比 */
170
170
  deposit_percentage?: string;
171
+ /** 关联的定金协议id */
172
+ self_deposit_policy_ids?: number[];
171
173
  /** 定金协议数据 */
172
174
  deposit_policy_data?: Array<{
173
175
  /** 定金协议id */
@@ -216,11 +216,6 @@ export declare const getProductDeposit: (params: {
216
216
  total: number;
217
217
  protocols: {
218
218
  id: number;
219
- /**
220
- * 格式化折扣到购物车
221
- * @param params 参数
222
- * @returns 格式化后的购物车
223
- */
224
219
  title: string;
225
220
  }[];
226
221
  } | null;
@@ -441,11 +441,16 @@ var getProductDeposit = (params) => {
441
441
  const { cartItem, product, bundle, options } = params;
442
442
  const num = (params == null ? void 0 : params.num) || 1;
443
443
  if (((_a = product == null ? void 0 : product.custom_deposit_data) == null ? void 0 : _a.has_deposit) == 1) {
444
- const protocols = [];
445
444
  let total = new import_decimal.default(0);
446
- const { deposit_fixed, deposit_percentage, deposit_policy_data } = (product == null ? void 0 : product.custom_deposit_data) || {};
447
- protocols.push(...deposit_policy_data || []);
445
+ const {
446
+ deposit_fixed,
447
+ deposit_percentage,
448
+ deposit_policy_data,
449
+ self_deposit_policy_ids
450
+ } = (product == null ? void 0 : product.custom_deposit_data) || {};
451
+ const allProtocols = deposit_policy_data || [];
448
452
  let productHasDeposit = false;
453
+ const protocolIds = [];
449
454
  if (typeof deposit_fixed === "string" && typeof deposit_percentage === "string") {
450
455
  const { depositTotal, result } = handleProductDeposit({
451
456
  depositData: product == null ? void 0 : product.custom_deposit_data,
@@ -454,17 +459,20 @@ var getProductDeposit = (params) => {
454
459
  });
455
460
  if (result) {
456
461
  total = depositTotal;
462
+ protocolIds.push(...self_deposit_policy_ids || []);
457
463
  productHasDeposit = true;
458
464
  }
459
465
  } else {
460
466
  if (bundle == null ? void 0 : bundle.length) {
461
- total = bundle.reduce((accumulator, currentBundleProduct) => {
467
+ total = bundle.reduce((accumulator, currBundleProduct) => {
468
+ const depositData = currBundleProduct == null ? void 0 : currBundleProduct.custom_deposit_data;
462
469
  const { depositTotal, result } = handleProductDeposit({
463
- depositData: currentBundleProduct == null ? void 0 : currentBundleProduct.custom_deposit_data,
464
- total: currentBundleProduct.price,
465
- num: currentBundleProduct.num
470
+ depositData,
471
+ total: currBundleProduct == null ? void 0 : currBundleProduct.price,
472
+ num: (currBundleProduct == null ? void 0 : currBundleProduct.num) || 1
466
473
  });
467
474
  if (result) {
475
+ protocolIds.push(...(depositData == null ? void 0 : depositData.self_deposit_policy_ids) || []);
468
476
  productHasDeposit = true;
469
477
  return accumulator.plus(depositTotal);
470
478
  }
@@ -473,6 +481,8 @@ var getProductDeposit = (params) => {
473
481
  }
474
482
  }
475
483
  if (productHasDeposit) {
484
+ const ids = new Set(protocolIds);
485
+ const protocols = allProtocols.filter((item) => ids.has(item.id));
476
486
  return { total: total.toNumber(), protocols };
477
487
  }
478
488
  return null;
@@ -168,6 +168,8 @@ export interface ProductData {
168
168
  deposit_fixed?: string;
169
169
  /** 定金百分比 */
170
170
  deposit_percentage?: string;
171
+ /** 关联的定金协议id */
172
+ self_deposit_policy_ids?: number[];
171
173
  /** 定金协议数据 */
172
174
  deposit_policy_data?: Array<{
173
175
  /** 定金协议id */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.16",
4
+ "version": "2.0.17",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",