@pisell/pisellos 2.0.15 → 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 */
@@ -1072,65 +1072,67 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
1072
1072
  // 更新购物车后,需要判定购物车里是否存在多个账号选择了相同资源的情况,如果是,且资源是单个预约,则要把选择了相同资源的 product._origin.resources 给去除
1073
1073
  var cartItems = this.store.cart.getItems();
1074
1074
  cartItems.forEach(function (item) {
1075
- var _item$_origin$resourc;
1076
- var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1077
- // 检查当前资源是否与目标资源的任何资源匹配
1078
- return !targetCartItem._origin.resources.some(function (targetRes) {
1079
- // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1080
- if (targetRes.resourceType !== 'single') {
1081
- var _item$_productOrigin2;
1082
- var _formatCapacity = formatDefaultCapacitys({
1083
- capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1084
- product_bundle: item._origin.product.product_bundle
1085
- });
1086
- var _currentCapacity = getSumCapacity({
1087
- capacity: _formatCapacity
1088
- });
1089
- var originResource = allOriginResources.find(function (n) {
1090
- return n.id === targetRes.id;
1091
- });
1092
- if (currentResourcesCapacityMap[targetRes.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1093
- return true;
1075
+ if (item._id !== targetCartItem._id) {
1076
+ var _item$_origin$resourc;
1077
+ var resources = (_item$_origin$resourc = item._origin.resources) === null || _item$_origin$resourc === void 0 ? void 0 : _item$_origin$resourc.filter(function (m) {
1078
+ // 检查当前资源是否与目标资源的任何资源匹配
1079
+ return !targetCartItem._origin.resources.some(function (targetRes) {
1080
+ // 如果新更新进来的资源不是单个预约,其实就不需要检测了资源重叠了,但是需要检测资源 capacity 是否足够
1081
+ if (targetRes.resourceType !== 'single') {
1082
+ var _item$_productOrigin2;
1083
+ var _formatCapacity = formatDefaultCapacitys({
1084
+ capacity: (_item$_productOrigin2 = item._productOrigin) === null || _item$_productOrigin2 === void 0 ? void 0 : _item$_productOrigin2.capacity,
1085
+ product_bundle: item._origin.product.product_bundle
1086
+ });
1087
+ var _currentCapacity = getSumCapacity({
1088
+ capacity: _formatCapacity
1089
+ });
1090
+ var originResource = allOriginResources.find(function (n) {
1091
+ return n.id === targetRes.id;
1092
+ });
1093
+ if (currentResourcesCapacityMap[targetRes.id] + _currentCapacity > (originResource === null || originResource === void 0 ? void 0 : originResource.capacity)) {
1094
+ return true;
1095
+ }
1096
+ currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1097
+ return false;
1098
+ }
1099
+ if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1100
+ var _targetRes$metadata$c, _m$metadata$combined_;
1101
+ // 检查主资源ID是否匹配
1102
+ if (targetRes.id === m.id) return true;
1103
+ // 检查组合资源的情况
1104
+ if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && (
1105
+ // 如果现在选择的是组合资源,需要判断
1106
+ // 1、当前其他购物车里是否选了当前组合资源的子资源
1107
+ // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1108
+ targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1109
+ return m.metadata.combined_resource.resource_ids.includes(n);
1110
+ }))) return true;
1111
+ if (((_m$metadata$combined_ = m.metadata.combined_resource) === null || _m$metadata$combined_ === void 0 ? void 0 : _m$metadata$combined_.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id)) return true;
1094
1112
  }
1095
- currentResourcesCapacityMap[targetRes.id] += _currentCapacity;
1096
1113
  return false;
1097
- }
1098
- if (item.holder_id !== (targetCartItem === null || targetCartItem === void 0 ? void 0 : targetCartItem.holder_id)) {
1099
- var _targetRes$metadata$c, _m$metadata$combined_;
1100
- // 检查主资源ID是否匹配
1101
- if (targetRes.id === m.id) return true;
1102
- // 检查组合资源的情况
1103
- if (((_targetRes$metadata$c = targetRes.metadata.combined_resource) === null || _targetRes$metadata$c === void 0 ? void 0 : _targetRes$metadata$c.status) === 1 && (
1104
- // 如果现在选择的是组合资源,需要判断
1105
- // 1、当前其他购物车里是否选了当前组合资源的子资源
1106
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
1107
- targetRes.metadata.combined_resource.resource_ids.includes(m.id) || targetRes.metadata.combined_resource.resource_ids.some(function (n) {
1108
- return m.metadata.combined_resource.resource_ids.includes(n);
1109
- }))) return true;
1110
- if (((_m$metadata$combined_ = m.metadata.combined_resource) === null || _m$metadata$combined_ === void 0 ? void 0 : _m$metadata$combined_.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id)) return true;
1111
- }
1112
- return false;
1113
- });
1114
- });
1115
- // session 类商品应该只调用清空 resource 的方法
1116
- if (item.start_time) {
1117
- var start_time = item.start_time;
1118
- var end_time = item.end_time;
1119
- var start_date = item.start_date;
1120
- var end_date = item.end_date;
1121
- _this5.store.cart.updateItem({
1122
- _id: item._id,
1123
- resources: resources,
1124
- date: {
1125
- startTime: dayjs("".concat(start_date, " ").concat(start_time)).format('YYYY-MM-DD HH:mm'),
1126
- endTime: dayjs("".concat(end_date, " ").concat(end_time)).format('YYYY-MM-DD HH:mm')
1127
- }
1128
- });
1129
- } else {
1130
- _this5.store.cart.updateItem({
1131
- _id: item._id,
1132
- resources: resources
1114
+ });
1133
1115
  });
1116
+ // session 类商品应该只调用清空 resource 的方法
1117
+ if (item.start_time) {
1118
+ var start_time = item.start_time;
1119
+ var end_time = item.end_time;
1120
+ var start_date = item.start_date;
1121
+ var end_date = item.end_date;
1122
+ _this5.store.cart.updateItem({
1123
+ _id: item._id,
1124
+ resources: resources,
1125
+ date: {
1126
+ startTime: dayjs("".concat(start_date, " ").concat(start_time)).format('YYYY-MM-DD HH:mm'),
1127
+ endTime: dayjs("".concat(end_date, " ").concat(end_time)).format('YYYY-MM-DD HH:mm')
1128
+ }
1129
+ });
1130
+ } else {
1131
+ _this5.store.cart.updateItem({
1132
+ _id: item._id,
1133
+ resources: resources
1134
+ });
1135
+ }
1134
1136
  }
1135
1137
  });
1136
1138
  }
@@ -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 */
@@ -530,62 +530,64 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
530
530
  const cartItems = this.store.cart.getItems();
531
531
  cartItems.forEach((item) => {
532
532
  var _a2;
533
- const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
534
- return !targetCartItem._origin.resources.some((targetRes) => {
535
- var _a3, _b, _c;
536
- if (targetRes.resourceType !== "single") {
537
- const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
538
- capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
539
- product_bundle: item._origin.product.product_bundle
540
- });
541
- const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
542
- const originResource = allOriginResources.find((n) => n.id === targetRes.id);
543
- if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
544
- return true;
533
+ if (item._id !== targetCartItem._id) {
534
+ const resources = (_a2 = item._origin.resources) == null ? void 0 : _a2.filter((m) => {
535
+ return !targetCartItem._origin.resources.some((targetRes) => {
536
+ var _a3, _b, _c;
537
+ if (targetRes.resourceType !== "single") {
538
+ const formatCapacity = (0, import_resources.formatDefaultCapacitys)({
539
+ capacity: (_a3 = item._productOrigin) == null ? void 0 : _a3.capacity,
540
+ product_bundle: item._origin.product.product_bundle
541
+ });
542
+ const currentCapacity = (0, import_resources.getSumCapacity)({ capacity: formatCapacity });
543
+ const originResource = allOriginResources.find((n) => n.id === targetRes.id);
544
+ if (currentResourcesCapacityMap[targetRes.id] + currentCapacity > (originResource == null ? void 0 : originResource.capacity)) {
545
+ return true;
546
+ }
547
+ currentResourcesCapacityMap[targetRes.id] += currentCapacity;
548
+ return false;
549
+ }
550
+ if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
551
+ if (targetRes.id === m.id)
552
+ return true;
553
+ if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
554
+ // 1、当前其他购物车里是否选了当前组合资源的子资源
555
+ // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
556
+ (targetRes.metadata.combined_resource.resource_ids.includes(
557
+ m.id
558
+ ) || targetRes.metadata.combined_resource.resource_ids.some(
559
+ (n) => {
560
+ return m.metadata.combined_resource.resource_ids.includes(
561
+ n
562
+ );
563
+ }
564
+ )))
565
+ return true;
566
+ if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
567
+ return true;
545
568
  }
546
- currentResourcesCapacityMap[targetRes.id] += currentCapacity;
547
569
  return false;
548
- }
549
- if (item.holder_id !== (targetCartItem == null ? void 0 : targetCartItem.holder_id)) {
550
- if (targetRes.id === m.id)
551
- return true;
552
- if (((_b = targetRes.metadata.combined_resource) == null ? void 0 : _b.status) === 1 && // 如果现在选择的是组合资源,需要判断
553
- // 1、当前其他购物车里是否选了当前组合资源的子资源
554
- // 2、如果其他购物车里的商品也是组合资源,出了组合资源本身的 id 需要判断,还需要判断子资源的 id 是否有交集
555
- (targetRes.metadata.combined_resource.resource_ids.includes(
556
- m.id
557
- ) || targetRes.metadata.combined_resource.resource_ids.some(
558
- (n) => {
559
- return m.metadata.combined_resource.resource_ids.includes(
560
- n
561
- );
562
- }
563
- )))
564
- return true;
565
- if (((_c = m.metadata.combined_resource) == null ? void 0 : _c.status) === 1 && m.metadata.combined_resource.resource_ids.includes(targetRes.id))
566
- return true;
567
- }
568
- return false;
569
- });
570
- });
571
- if (item.start_time) {
572
- const start_time = item.start_time;
573
- const end_time = item.end_time;
574
- const start_date = item.start_date;
575
- const end_date = item.end_date;
576
- this.store.cart.updateItem({
577
- _id: item._id,
578
- resources,
579
- date: {
580
- startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
581
- endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
582
- }
583
- });
584
- } else {
585
- this.store.cart.updateItem({
586
- _id: item._id,
587
- resources
570
+ });
588
571
  });
572
+ if (item.start_time) {
573
+ const start_time = item.start_time;
574
+ const end_time = item.end_time;
575
+ const start_date = item.start_date;
576
+ const end_date = item.end_date;
577
+ this.store.cart.updateItem({
578
+ _id: item._id,
579
+ resources,
580
+ date: {
581
+ startTime: (0, import_dayjs.default)(`${start_date} ${start_time}`).format("YYYY-MM-DD HH:mm"),
582
+ endTime: (0, import_dayjs.default)(`${end_date} ${end_time}`).format("YYYY-MM-DD HH:mm")
583
+ }
584
+ });
585
+ } else {
586
+ this.store.cart.updateItem({
587
+ _id: item._id,
588
+ resources
589
+ });
590
+ }
589
591
  }
590
592
  });
591
593
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.0.15",
4
+ "version": "2.0.17",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",