@pisell/pisellos 0.0.85 → 0.0.87

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.
@@ -25,7 +25,8 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
25
25
  productList: any[];
26
26
  }, options?: {
27
27
  isSelected?: boolean;
28
- discountId: number;
28
+ discountId?: number;
29
+ scan?: boolean;
29
30
  }): DiscountResult;
30
31
  destroy(): Promise<void>;
31
32
  clear(): Promise<void>;
@@ -111,6 +111,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
111
111
  var result = this.calcDiscount({
112
112
  discountList: mergedDiscountList,
113
113
  productList: _toConsumableArray(productList)
114
+ }, {
115
+ scan: true
114
116
  });
115
117
 
116
118
  // 检查是否有产品使用了新折扣
@@ -308,7 +310,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
308
310
  }
309
311
  return;
310
312
  }
311
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined') {
313
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === 'undefined' && !(options !== null && options !== void 0 && options.scan)) {
312
314
  return;
313
315
  }
314
316
 
@@ -366,7 +368,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
366
368
  var product = _this3.hooks.getProduct(originProduct);
367
369
  var getDefaultProduct = function getDefaultProduct() {
368
370
  if (product.isClient) {
369
- _this3.hooks.setProduct(originProduct, {
371
+ return _this3.hooks.setProduct(originProduct, {
370
372
  discount_list: [],
371
373
  price: product.price,
372
374
  origin_total: getProductOriginTotalPrice({
@@ -385,7 +387,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
385
387
  })
386
388
  });
387
389
  } else {
388
- _this3.hooks.setProduct(originProduct, {
390
+ return _this3.hooks.setProduct(originProduct, {
389
391
  discount_list: [],
390
392
  total: product.total,
391
393
  origin_total: product.origin_total,
@@ -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
  }
@@ -25,7 +25,8 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
25
25
  productList: any[];
26
26
  }, options?: {
27
27
  isSelected?: boolean;
28
- discountId: number;
28
+ discountId?: number;
29
+ scan?: boolean;
29
30
  }): DiscountResult;
30
31
  destroy(): Promise<void>;
31
32
  clear(): Promise<void>;
@@ -65,6 +65,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
65
65
  const result = this.calcDiscount({
66
66
  discountList: mergedDiscountList,
67
67
  productList: [...productList]
68
+ }, {
69
+ scan: true
68
70
  });
69
71
  let hasApplicableDiscount = false;
70
72
  const newDiscountIds = newDiscountList.map((discount) => discount.id);
@@ -213,7 +215,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
213
215
  }
214
216
  return;
215
217
  }
216
- if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined") {
218
+ if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
217
219
  return;
218
220
  }
219
221
  usedDiscounts.set(selectedDiscount.id, true);
@@ -268,7 +270,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
268
270
  const product = this.hooks.getProduct(originProduct);
269
271
  const getDefaultProduct = () => {
270
272
  if (product.isClient) {
271
- this.hooks.setProduct(originProduct, {
273
+ return this.hooks.setProduct(originProduct, {
272
274
  discount_list: [],
273
275
  price: product.price,
274
276
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
@@ -287,7 +289,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
287
289
  })
288
290
  });
289
291
  } else {
290
- this.hooks.setProduct(originProduct, {
292
+ return this.hooks.setProduct(originProduct, {
291
293
  discount_list: [],
292
294
  total: product.total,
293
295
  origin_total: product.origin_total,
@@ -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": "0.0.85",
4
+ "version": "0.0.87",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",