@pisell/pisellos 0.0.150 → 0.0.151

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.
@@ -262,7 +262,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
262
262
 
263
263
  // 编辑的商品 使用了优惠券不可用
264
264
  var isAvailableProduct = !(product !== null && product !== void 0 && product.booking_id && product !== null && product !== void 0 && (_product$discount_lis = product.discount_list) !== null && _product$discount_lis !== void 0 && _product$discount_lis.length && product !== null && product !== void 0 && (_product$discount_lis2 = product.discount_list) !== null && _product$discount_lis2 !== void 0 && _product$discount_lis2.every(function (discount) {
265
- return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag);
265
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
266
266
  }));
267
267
 
268
268
  // 判断优惠券是否适用于该商品
@@ -275,7 +275,8 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
275
275
  var applicableProducts = discountApplicableProducts.get(discount.id) || [];
276
276
  applicableProducts.push({
277
277
  amount: product.price,
278
- type: discount.tag,
278
+ type: discount.tag || discount.type,
279
+ tag: discount.tag || discount.type,
279
280
  discount: {
280
281
  resource_id: discount.id,
281
282
  title: discount.format_title,
@@ -296,7 +297,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
296
297
  var _product$discount_lis3, _product$discount_lis4, _product$discount_lis5, _product$discount_lis6, _product$discount_lis7;
297
298
  var product = _this3.hooks.getProduct(originProduct);
298
299
  if (product !== null && product !== void 0 && product.booking_id && (_product$discount_lis3 = product.discount_list) !== null && _product$discount_lis3 !== void 0 && _product$discount_lis3.length && product !== null && product !== void 0 && (_product$discount_lis4 = product.discount_list) !== null && _product$discount_lis4 !== void 0 && _product$discount_lis4.every(function (discount) {
299
- return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag);
300
+ return discount.id && ['good_pass', 'discount_card', 'product_discount_card'].includes(discount.tag || discount.type);
300
301
  })) {
301
302
  processedProductsMap.set(product._id, [originProduct]);
302
303
  return;
@@ -308,7 +309,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
308
309
  if (Number(product.price) === 0 || !product.price) return false;
309
310
  // 如果优惠券已被使用,则跳过
310
311
  var targetUsedDiscounts = usedDiscounts.get(discount.id);
311
- if (targetUsedDiscounts && discount.tag === 'good_pass') return false;
312
+ if (targetUsedDiscounts && (discount.tag || discount.type) === 'good_pass') return false;
312
313
  var limitedData = discount.limited_relation_product_data;
313
314
 
314
315
  // 判断优惠券是否适用于该商品
@@ -373,11 +374,15 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
373
374
  return;
374
375
  }
375
376
 
377
+ // 是否需要拆分
378
+ var isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === 'good_pass';
379
+
376
380
  // 需要拆分出来的数量
377
- var splitCount = Math.min(product.quantity, applicableDiscounts.length);
378
- debugger;
381
+ var splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter(function (item) {
382
+ return (item.tag || item.type) === 'good_pass';
383
+ }).length) : 1;
379
384
  var arr = [];
380
- if (splitCount < product.quantity) {
385
+ if (splitCount < product.quantity && isNeedSplit) {
381
386
  arr.push(_this3.hooks.setProduct(originProduct, {
382
387
  discount_list: [],
383
388
  quantity: product.quantity - splitCount,
@@ -413,7 +418,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
413
418
  arr.push(_this3.hooks.setProduct(originProduct, {
414
419
  discount_list: [discountDetail],
415
420
  price: new Decimal(targetProductPrice).toNumber(),
416
- quantity: 1,
421
+ quantity: isNeedSplit ? 1 : product.quantity,
417
422
  origin_total: getProductOriginTotalPrice({
418
423
  product: {
419
424
  original_price: product.original_price
@@ -434,7 +439,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
434
439
  discount_list: [discountDetail],
435
440
  _id: product._id.split('___')[0] + "___" + _selectedDiscount.id,
436
441
  price: new Decimal(targetProductPrice).toNumber(),
437
- quantity: 1,
442
+ quantity: isNeedSplit ? 1 : product.quantity,
438
443
  total: new Decimal(product.origin_total || product.total || 0).minus(new Decimal(product.price || 0).minus(new Decimal(targetProductPrice))).toNumber(),
439
444
  origin_total: product.origin_total || product.total
440
445
  }));
@@ -478,7 +483,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
478
483
  }
479
484
  };
480
485
  var arr = processedProductsMap.get(product._id);
481
- arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
486
+ arr !== null && arr !== void 0 && arr.length ? processedProductList.push.apply(processedProductList, _toConsumableArray(arr)) : processedProductList.push(getDefaultProduct());
482
487
  });
483
488
 
484
489
  // 按原始顺序更新优惠券列表,标记已使用和可用的优惠券
@@ -2242,7 +2242,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2242
2242
  break;
2243
2243
  }
2244
2244
  dateRange = this.store.date.getDateRange(); // 如果不是先选日期的流程 duration 商品就啥也不做
2245
- if (dateRange.length) {
2245
+ if (dateRange !== null && dateRange !== void 0 && dateRange.length) {
2246
2246
  _context25.next = 15;
2247
2247
  break;
2248
2248
  }
@@ -2876,6 +2876,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2876
2876
  }, {
2877
2877
  key: "isTargetNormalProduct",
2878
2878
  value: function isTargetNormalProduct(product) {
2879
+ if (!product) return false;
2879
2880
  return isNormalProduct(product);
2880
2881
  }
2881
2882
  }, {
@@ -444,7 +444,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
444
444
  if (discount.id && ['good_pass', 'discount_card'].includes(discount.type)) {
445
445
  var index = editModeDiscountList.findIndex(function (n) {
446
446
  var _discount$discount;
447
- return n.id === ((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id;
447
+ return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
448
448
  });
449
449
  if (index !== -1) {
450
450
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
@@ -171,13 +171,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
171
171
  var _a, _b, _c;
172
172
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
173
173
  const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
174
- const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag))));
174
+ const isAvailableProduct = !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type))));
175
175
  if (isAvailableProduct && isLimitedProduct) {
176
176
  (_c = discountApplicability.get(discount.id)) == null ? void 0 : _c.push(product.id);
177
177
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
178
178
  applicableProducts.push({
179
179
  amount: product.price,
180
- type: discount.tag,
180
+ type: discount.tag || discount.type,
181
+ tag: discount.tag || discount.type,
181
182
  discount: {
182
183
  resource_id: discount.id,
183
184
  title: discount.format_title,
@@ -195,7 +196,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
195
196
  sortedProductList.forEach((originProduct, i) => {
196
197
  var _a, _b, _c, _d, _e;
197
198
  const product = this.hooks.getProduct(originProduct);
198
- if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag)))) {
199
+ if ((product == null ? void 0 : product.booking_id) && ((_a = product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
199
200
  processedProductsMap.set(product._id, [originProduct]);
200
201
  return;
201
202
  }
@@ -203,7 +204,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
203
204
  if (Number(product.price) === 0 || !product.price)
204
205
  return false;
205
206
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
206
- if (targetUsedDiscounts && discount.tag === "good_pass")
207
+ if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
207
208
  return false;
208
209
  const limitedData = discount.limited_relation_product_data;
209
210
  if (limitedData.type === "product_all") {
@@ -264,10 +265,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
264
265
  if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan)) {
265
266
  return;
266
267
  }
267
- const splitCount = Math.min(product.quantity, applicableDiscounts.length);
268
- debugger;
268
+ const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
269
+ const splitCount = isNeedSplit ? Math.min(product.quantity, applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length) : 1;
269
270
  const arr = [];
270
- if (splitCount < product.quantity) {
271
+ if (splitCount < product.quantity && isNeedSplit) {
271
272
  arr.push(this.hooks.setProduct(originProduct, {
272
273
  discount_list: [],
273
274
  quantity: product.quantity - splitCount,
@@ -297,7 +298,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
297
298
  arr.push(this.hooks.setProduct(originProduct, {
298
299
  discount_list: [discountDetail],
299
300
  price: new import_decimal.default(targetProductPrice).toNumber(),
300
- quantity: 1,
301
+ quantity: isNeedSplit ? 1 : product.quantity,
301
302
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
302
303
  product: {
303
304
  original_price: product.original_price
@@ -318,7 +319,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
318
319
  discount_list: [discountDetail],
319
320
  _id: product._id.split("___")[0] + "___" + selectedDiscount2.id,
320
321
  price: new import_decimal.default(targetProductPrice).toNumber(),
321
- quantity: 1,
322
+ quantity: isNeedSplit ? 1 : product.quantity,
322
323
  total: new import_decimal.default(product.origin_total || product.total || 0).minus(new import_decimal.default(product.price || 0).minus(new import_decimal.default(targetProductPrice))).toNumber(),
323
324
  origin_total: product.origin_total || product.total
324
325
  }));
@@ -360,7 +361,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
360
361
  }
361
362
  };
362
363
  const arr = processedProductsMap.get(product._id);
363
- arr.length ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
364
+ (arr == null ? void 0 : arr.length) ? processedProductList.push(...arr) : processedProductList.push(getDefaultProduct());
364
365
  });
365
366
  const updatedDiscountList = addModeDiscount.map((discount) => {
366
367
  const applicableProducts = discountApplicability.get(discount.id) || [];
@@ -1562,7 +1562,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1562
1562
  targetProduct.setOtherParams("schedule", newScheduleArr);
1563
1563
  } else if (targetProductData.duration) {
1564
1564
  const dateRange = this.store.date.getDateRange();
1565
- if (!dateRange.length)
1565
+ if (!(dateRange == null ? void 0 : dateRange.length))
1566
1566
  return;
1567
1567
  this.getAvailableDate({
1568
1568
  startDate: dateRange[0].date,
@@ -2034,6 +2034,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
2034
2034
  });
2035
2035
  }
2036
2036
  isTargetNormalProduct(product) {
2037
+ if (!product)
2038
+ return false;
2037
2039
  return (0, import_utils4.isNormalProduct)(product);
2038
2040
  }
2039
2041
  isTargetCartIdNormalProduct(id) {
@@ -289,7 +289,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
289
289
  if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
290
290
  const index = editModeDiscountList.findIndex((n) => {
291
291
  var _a4;
292
- return n.id === ((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id;
292
+ return n.id === (((_a4 = discount.discount) == null ? void 0 : _a4.resource_id) || discount.id);
293
293
  });
294
294
  if (index !== -1) {
295
295
  editModeDiscountList[index] = {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.150",
4
+ "version": "0.0.151",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",