@pisell/pisellos 0.0.462 → 0.0.464

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.
@@ -1453,19 +1453,239 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1453
1453
  }));
1454
1454
  }
1455
1455
 
1456
- // 生成无折扣的商品(剩余数量)
1457
- if (normalNum > 0) {
1458
- processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1459
- // 🔥 为剩余商品生成唯一的 _id
1460
- _id: "".concat(flatItem._id, "_split_rest"),
1461
- num: normalNum,
1462
- quantity: normalNum,
1463
- discount_list: [],
1464
- processed: true
1465
- }));
1456
+ // 🔥 对拆分后的剩余商品继续匹配其他可用折扣(而不是等到下次执行才应用)
1457
+ var remainingNum = normalNum;
1458
+ var continueSplitIndex = discountNum;
1459
+ while (remainingNum > 0) {
1460
+ var _nextSelectedDiscount;
1461
+ // 重新查找适用于剩余商品的可用折扣(已使用的会被自动过滤掉)
1462
+ var nextApplicableDiscounts = sortedDiscountList.filter(function (nextDiscount) {
1463
+ var _product$discount_lis10;
1464
+ var nextDiscountType = nextDiscount.tag || nextDiscount.type;
1465
+ // 检查策略可用性
1466
+ if (['good_pass', 'discount_card', 'product_discount_card'].includes(nextDiscountType)) {
1467
+ var _nextDiscount$config;
1468
+ if (nextDiscount.config === undefined || !(nextDiscount !== null && nextDiscount !== void 0 && (_nextDiscount$config = nextDiscount.config) !== null && _nextDiscount$config !== void 0 && _nextDiscount$config.isAvailable)) {
1469
+ return false;
1470
+ }
1471
+ }
1472
+ // 折扣卡时总价为0时不可用
1473
+ if ((Number(product.total) <= 0 || !product.total) && !((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.find(function (n) {
1474
+ var _n$discount2;
1475
+ return ((_n$discount2 = n.discount) === null || _n$discount2 === void 0 ? void 0 : _n$discount2.resource_id) === nextDiscount.id;
1476
+ })) && nextDiscountType !== 'good_pass') return false;
1477
+
1478
+ // 商品券已被使用则跳过
1479
+ if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === 'good_pass') return false;
1480
+
1481
+ // 检查 maxUsagePerOrder 限制
1482
+ if (nextDiscountType === 'good_pass') {
1483
+ var _nextDiscount$config2;
1484
+ var maxUsagePerOrder = (_nextDiscount$config2 = nextDiscount.config) === null || _nextDiscount$config2 === void 0 ? void 0 : _nextDiscount$config2.maxUsagePerOrder;
1485
+ if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1486
+ var currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
1487
+ if (currentUsedCount >= maxUsagePerOrder) {
1488
+ return false;
1489
+ }
1490
+ }
1491
+ }
1492
+
1493
+ // 检查折扣卡的 applicableProductLimit 限制
1494
+ if (['discount_card', 'product_discount_card'].includes(nextDiscountType)) {
1495
+ var _nextDiscount$config3;
1496
+ var limitConfig = ((_nextDiscount$config3 = nextDiscount.config) === null || _nextDiscount$config3 === void 0 ? void 0 : _nextDiscount$config3.applicableProductLimit) || 0;
1497
+ if (limitConfig > 0) {
1498
+ var currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
1499
+ if (currentUsedLimitCount >= limitConfig) {
1500
+ return false;
1501
+ }
1502
+ }
1503
+ }
1504
+ var limitedData = nextDiscount.limited_relation_product_data;
1505
+ if (limitedData.type === 'product_all') {
1506
+ if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1507
+ return false;
1508
+ }
1509
+ if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1510
+ return false;
1511
+ }
1512
+ return true;
1513
+ } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
1514
+ if (!_this3.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1515
+ return false;
1516
+ }
1517
+ return true;
1518
+ }
1519
+ return false;
1520
+ });
1521
+
1522
+ // 没有更多可用折扣,剩余商品无折扣存储
1523
+ if (nextApplicableDiscounts.length === 0) {
1524
+ processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1525
+ _id: "".concat(flatItem._id, "_split_rest"),
1526
+ num: remainingNum,
1527
+ quantity: remainingNum,
1528
+ discount_list: [],
1529
+ processed: true
1530
+ }));
1531
+ break;
1532
+ }
1533
+
1534
+ // 选择最优折扣
1535
+ var nextSelectedDiscountCard = nextApplicableDiscounts.find(function (n) {
1536
+ return n.isScan && n.isSelected && (n.tag || n.type) !== 'good_pass';
1537
+ });
1538
+ var nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1539
+
1540
+ // 判断新折扣是否需要拆分
1541
+ var nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
1542
+ var nextIsGoodPass = nextDiscType === 'good_pass';
1543
+ var nextIsDiscountCard = ['discount_card', 'product_discount_card'].includes(nextDiscType);
1544
+ var nextApplicableProductLimit = ((_nextSelectedDiscount = nextSelectedDiscount.config) === null || _nextSelectedDiscount === void 0 ? void 0 : _nextSelectedDiscount.applicableProductLimit) || 0;
1545
+ var nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
1546
+ if (!nextIsNeedSplit) {
1547
+ var _nextBundleDiscount$m, _flatItem$parentProdu9;
1548
+ // 🔥 不需要拆分:直接应用折扣到所有剩余商品
1549
+ var nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1550
+ usedDiscounts.set(nextBundleDiscount.id, true);
1551
+ if ((nextBundleDiscount.tag || nextBundleDiscount.type) === 'good_pass') {
1552
+ var curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1553
+ usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1554
+ }
1555
+ var nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
1556
+ if (['discount_card', 'product_discount_card'].includes(nextNoSplitType)) {
1557
+ var _curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1558
+ usedDiscountCardLimitCounts.set(nextBundleDiscount.id, _curCount + remainingNum);
1559
+ }
1560
+ var nextOriginTotal = product.original_price || product.price || 0;
1561
+ var nextTargetTotal = getDiscountAmount(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
1562
+ var nextDiscountAmount = new Decimal(nextOriginTotal).minus(nextTargetTotal).toNumber();
1563
+ var nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
1564
+ var nextBundleDiscType = nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : nextBundleDiscount.tag;
1565
+ var nextDiscountDetail = {
1566
+ amount: nextDiscountAmount * remainingNum,
1567
+ type: nextBundleDiscType,
1568
+ discount: {
1569
+ discount_card_type: nextBundleDiscount === null || nextBundleDiscount === void 0 || (_nextBundleDiscount$m = nextBundleDiscount.metadata) === null || _nextBundleDiscount$m === void 0 ? void 0 : _nextBundleDiscount$m.discount_card_type,
1570
+ fixed_amount: nextDiscountAmount,
1571
+ resource_id: nextBundleDiscount.id,
1572
+ title: nextBundleDiscount.format_title,
1573
+ original_amount: product.original_price,
1574
+ product_id: product.id,
1575
+ percent: nextBundleDiscount.par_value,
1576
+ discount_product_id: nextBundleDiscount.product_id
1577
+ },
1578
+ metadata: {
1579
+ custom_product_bundle_map_id: nextUniqueId,
1580
+ num: remainingNum
1581
+ },
1582
+ config: nextBundleDiscount === null || nextBundleDiscount === void 0 ? void 0 : nextBundleDiscount.config,
1583
+ _num: remainingNum * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1584
+ };
1585
+ var nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1586
+ nextAppliedProducts.push(nextDiscountDetail);
1587
+ appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1588
+ processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1589
+ _id: nextUniqueId,
1590
+ num: remainingNum,
1591
+ quantity: remainingNum,
1592
+ total: nextTargetTotal,
1593
+ price: new Decimal(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
1594
+ discount_list: [nextDiscountDetail],
1595
+ processed: true
1596
+ }));
1597
+ remainingNum = 0;
1598
+ break;
1599
+ }
1600
+
1601
+ // 🔥 需要拆分:计算最大使用次数
1602
+ var nextMaxUsageLimit = void 0;
1603
+ if (nextIsGoodPass) {
1604
+ var _nextSelectedDiscount2;
1605
+ var nextGoodPassCount = nextApplicableDiscounts.filter(function (item) {
1606
+ return (item.tag || item.type) === 'good_pass';
1607
+ }).length;
1608
+ nextMaxUsageLimit = nextGoodPassCount;
1609
+ if ((_nextSelectedDiscount2 = nextSelectedDiscount.config) !== null && _nextSelectedDiscount2 !== void 0 && _nextSelectedDiscount2.maxUsagePerOrder) {
1610
+ var usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
1611
+ nextMaxUsageLimit = Math.min(nextGoodPassCount, Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount));
1612
+ }
1613
+ } else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
1614
+ var _usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
1615
+ nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - _usedLimitCount);
1616
+ } else {
1617
+ nextMaxUsageLimit = 1;
1618
+ }
1619
+ var nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
1620
+ if (nextSplitCount === 0) {
1621
+ // 已达使用上限,剩余商品无折扣存储
1622
+ processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1623
+ _id: "".concat(flatItem._id, "_split_rest"),
1624
+ num: remainingNum,
1625
+ quantity: remainingNum,
1626
+ discount_list: [],
1627
+ processed: true
1628
+ }));
1629
+ break;
1630
+ }
1631
+
1632
+ // 生成有折扣的商品
1633
+ for (var j = 0; j < nextSplitCount; j++) {
1634
+ var _nextBundleDiscount$m2;
1635
+ var _nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
1636
+ usedDiscounts.set(_nextBundleDiscount.id, true);
1637
+ if ((_nextBundleDiscount.tag || _nextBundleDiscount.type) === 'good_pass') {
1638
+ var _curCount2 = usedProductIdCounts.get(_nextBundleDiscount.product_id) || 0;
1639
+ usedProductIdCounts.set(_nextBundleDiscount.product_id, _curCount2 + 1);
1640
+ }
1641
+ var nextBundleDiscTypeForCount = _nextBundleDiscount.tag || _nextBundleDiscount.type;
1642
+ if (['discount_card', 'product_discount_card'].includes(nextBundleDiscTypeForCount)) {
1643
+ var curLimitCount = usedDiscountCardLimitCounts.get(_nextBundleDiscount.id) || 0;
1644
+ usedDiscountCardLimitCounts.set(_nextBundleDiscount.id, curLimitCount + 1);
1645
+ }
1646
+ var _nextUniqueId = "".concat(flatItem._id, "_split_").concat(continueSplitIndex);
1647
+ var nextDiscountedPrice = getDiscountAmount(_nextBundleDiscount, product.origin_total, product.origin_total);
1648
+ var nextBundleDiscAmount = new Decimal(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
1649
+ var nextBundleDiscTypeStr = _nextBundleDiscount.tag === 'product_discount_card' ? 'discount_card' : _nextBundleDiscount.tag;
1650
+ var _nextDiscountDetail = {
1651
+ amount: nextBundleDiscAmount,
1652
+ type: nextBundleDiscTypeStr,
1653
+ discount: {
1654
+ discount_card_type: _nextBundleDiscount === null || _nextBundleDiscount === void 0 || (_nextBundleDiscount$m2 = _nextBundleDiscount.metadata) === null || _nextBundleDiscount$m2 === void 0 ? void 0 : _nextBundleDiscount$m2.discount_card_type,
1655
+ fixed_amount: nextBundleDiscAmount,
1656
+ resource_id: _nextBundleDiscount.id,
1657
+ title: _nextBundleDiscount.format_title,
1658
+ original_amount: product.origin_total,
1659
+ product_id: product.id,
1660
+ percent: _nextBundleDiscount.par_value,
1661
+ discount_product_id: _nextBundleDiscount.product_id
1662
+ },
1663
+ metadata: {
1664
+ custom_product_bundle_map_id: _nextUniqueId,
1665
+ num: 1
1666
+ },
1667
+ _num: 1,
1668
+ config: _nextBundleDiscount === null || _nextBundleDiscount === void 0 ? void 0 : _nextBundleDiscount.config
1669
+ };
1670
+ var _nextAppliedProducts = appliedDiscountProducts.get(_nextBundleDiscount.id) || [];
1671
+ _nextAppliedProducts.push(_nextDiscountDetail);
1672
+ appliedDiscountProducts.set(_nextBundleDiscount.id, _nextAppliedProducts);
1673
+ processedItems.push(_objectSpread(_objectSpread({}, flatItem), {}, {
1674
+ _id: _nextUniqueId,
1675
+ num: 1,
1676
+ quantity: 1,
1677
+ price: nextDiscountedPrice,
1678
+ total: nextDiscountedPrice,
1679
+ discount_list: [_nextDiscountDetail],
1680
+ processed: true,
1681
+ _discountId: _nextBundleDiscount.id
1682
+ }));
1683
+ continueSplitIndex++;
1684
+ }
1685
+ remainingNum -= nextSplitCount;
1466
1686
  }
1467
1687
  } else {
1468
- var _currentBundleDiscoun3, _currentBundleDiscoun4, _flatItem$parentProdu9;
1688
+ var _currentBundleDiscoun3, _currentBundleDiscoun4, _flatItem$parentProdu10;
1469
1689
  // 不拆分:直接应用折扣
1470
1690
  var _currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
1471
1691
  usedDiscounts.set(_currentBundleDiscount.id, true);
@@ -1529,7 +1749,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1529
1749
  product_discount_difference: _productDiscountDifference
1530
1750
  }),
1531
1751
  config: _currentBundleDiscount === null || _currentBundleDiscount === void 0 ? void 0 : _currentBundleDiscount.config,
1532
- _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu9 = flatItem.parentProduct) === null || _flatItem$parentProdu9 === void 0 ? void 0 : _flatItem$parentProdu9.num) || 1)
1752
+ _num: (product.num || 1) * ((flatItem === null || flatItem === void 0 || (_flatItem$parentProdu10 = flatItem.parentProduct) === null || _flatItem$parentProdu10 === void 0 ? void 0 : _flatItem$parentProdu10.num) || 1)
1533
1753
  };
1534
1754
 
1535
1755
  // 记录实际应用的折扣
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 1 | 2 | 3 | 5 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -2568,8 +2568,12 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2568
2568
  _step3;
2569
2569
  try {
2570
2570
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
2571
+ var _time$event_list;
2571
2572
  var time = _step3.value;
2572
- var _iterator4 = _createForOfIteratorHelper(time.event_list || []),
2573
+ var blockedTimes = (_time$event_list = time.event_list) === null || _time$event_list === void 0 ? void 0 : _time$event_list.filter(function (event) {
2574
+ return event.type !== 'schedule_event';
2575
+ });
2576
+ var _iterator4 = _createForOfIteratorHelper(blockedTimes || []),
2573
2577
  _step4;
2574
2578
  try {
2575
2579
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
@@ -634,7 +634,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
634
634
  });
635
635
  const processedFlatItemsMap = /* @__PURE__ */ new Map();
636
636
  sortedFlattenedList.forEach((flatItem, index) => {
637
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E;
637
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J;
638
638
  let product, originProduct;
639
639
  if (flatItem.type === "main") {
640
640
  product = flatItem.product;
@@ -1103,16 +1103,222 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1103
1103
  _discountId: currentBundleDiscount.id
1104
1104
  });
1105
1105
  }
1106
- if (normalNum > 0) {
1107
- processedItems.push({
1108
- ...flatItem,
1109
- // 🔥 为剩余商品生成唯一的 _id
1110
- _id: `${flatItem._id}_split_rest`,
1111
- num: normalNum,
1112
- quantity: normalNum,
1113
- discount_list: [],
1114
- processed: true
1106
+ let remainingNum = normalNum;
1107
+ let continueSplitIndex = discountNum;
1108
+ while (remainingNum > 0) {
1109
+ const nextApplicableDiscounts = sortedDiscountList.filter((nextDiscount) => {
1110
+ var _a2, _b2, _c2, _d2;
1111
+ const nextDiscountType = nextDiscount.tag || nextDiscount.type;
1112
+ if (["good_pass", "discount_card", "product_discount_card"].includes(nextDiscountType)) {
1113
+ if (nextDiscount.config === void 0 || !((_a2 = nextDiscount == null ? void 0 : nextDiscount.config) == null ? void 0 : _a2.isAvailable)) {
1114
+ return false;
1115
+ }
1116
+ }
1117
+ if ((Number(product.total) <= 0 || !product.total) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find(
1118
+ (n) => {
1119
+ var _a3;
1120
+ return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === nextDiscount.id;
1121
+ }
1122
+ )) && nextDiscountType !== "good_pass")
1123
+ return false;
1124
+ if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === "good_pass")
1125
+ return false;
1126
+ if (nextDiscountType === "good_pass") {
1127
+ const maxUsagePerOrder = (_c2 = nextDiscount.config) == null ? void 0 : _c2.maxUsagePerOrder;
1128
+ if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1129
+ const currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
1130
+ if (currentUsedCount >= maxUsagePerOrder) {
1131
+ return false;
1132
+ }
1133
+ }
1134
+ }
1135
+ if (["discount_card", "product_discount_card"].includes(nextDiscountType)) {
1136
+ const limitConfig = ((_d2 = nextDiscount.config) == null ? void 0 : _d2.applicableProductLimit) || 0;
1137
+ if (limitConfig > 0) {
1138
+ const currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
1139
+ if (currentUsedLimitCount >= limitConfig) {
1140
+ return false;
1141
+ }
1142
+ }
1143
+ }
1144
+ const limitedData = nextDiscount.limited_relation_product_data;
1145
+ if (limitedData.type === "product_all") {
1146
+ if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1147
+ return false;
1148
+ }
1149
+ if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1150
+ return false;
1151
+ }
1152
+ return true;
1153
+ } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
1154
+ if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1155
+ return false;
1156
+ }
1157
+ return true;
1158
+ }
1159
+ return false;
1115
1160
  });
1161
+ if (nextApplicableDiscounts.length === 0) {
1162
+ processedItems.push({
1163
+ ...flatItem,
1164
+ _id: `${flatItem._id}_split_rest`,
1165
+ num: remainingNum,
1166
+ quantity: remainingNum,
1167
+ discount_list: [],
1168
+ processed: true
1169
+ });
1170
+ break;
1171
+ }
1172
+ const nextSelectedDiscountCard = nextApplicableDiscounts.find(
1173
+ (n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
1174
+ );
1175
+ const nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1176
+ const nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
1177
+ const nextIsGoodPass = nextDiscType === "good_pass";
1178
+ const nextIsDiscountCard = ["discount_card", "product_discount_card"].includes(nextDiscType);
1179
+ const nextApplicableProductLimit = ((_C = nextSelectedDiscount.config) == null ? void 0 : _C.applicableProductLimit) || 0;
1180
+ const nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
1181
+ if (!nextIsNeedSplit) {
1182
+ const nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1183
+ usedDiscounts.set(nextBundleDiscount.id, true);
1184
+ if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
1185
+ const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1186
+ usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1187
+ }
1188
+ const nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
1189
+ if (["discount_card", "product_discount_card"].includes(nextNoSplitType)) {
1190
+ const curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1191
+ usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curCount + remainingNum);
1192
+ }
1193
+ const nextOriginTotal = product.original_price || product.price || 0;
1194
+ const nextTargetTotal = (0, import_utils.getDiscountAmount)(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
1195
+ const nextDiscountAmount = new import_decimal.default(nextOriginTotal).minus(nextTargetTotal).toNumber();
1196
+ const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
1197
+ const nextBundleDiscType = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
1198
+ const nextDiscountDetail = {
1199
+ amount: nextDiscountAmount * remainingNum,
1200
+ type: nextBundleDiscType,
1201
+ discount: {
1202
+ discount_card_type: (_D = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _D.discount_card_type,
1203
+ fixed_amount: nextDiscountAmount,
1204
+ resource_id: nextBundleDiscount.id,
1205
+ title: nextBundleDiscount.format_title,
1206
+ original_amount: product.original_price,
1207
+ product_id: product.id,
1208
+ percent: nextBundleDiscount.par_value,
1209
+ discount_product_id: nextBundleDiscount.product_id
1210
+ },
1211
+ metadata: {
1212
+ custom_product_bundle_map_id: nextUniqueId,
1213
+ num: remainingNum
1214
+ },
1215
+ config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config,
1216
+ _num: remainingNum * (((_E = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _E.num) || 1)
1217
+ };
1218
+ const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1219
+ nextAppliedProducts.push(nextDiscountDetail);
1220
+ appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1221
+ processedItems.push({
1222
+ ...flatItem,
1223
+ _id: nextUniqueId,
1224
+ num: remainingNum,
1225
+ quantity: remainingNum,
1226
+ total: nextTargetTotal,
1227
+ price: new import_decimal.default(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
1228
+ discount_list: [nextDiscountDetail],
1229
+ processed: true
1230
+ });
1231
+ remainingNum = 0;
1232
+ break;
1233
+ }
1234
+ let nextMaxUsageLimit;
1235
+ if (nextIsGoodPass) {
1236
+ const nextGoodPassCount = nextApplicableDiscounts.filter(
1237
+ (item) => (item.tag || item.type) === "good_pass"
1238
+ ).length;
1239
+ nextMaxUsageLimit = nextGoodPassCount;
1240
+ if ((_F = nextSelectedDiscount.config) == null ? void 0 : _F.maxUsagePerOrder) {
1241
+ const usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
1242
+ nextMaxUsageLimit = Math.min(
1243
+ nextGoodPassCount,
1244
+ Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount)
1245
+ );
1246
+ }
1247
+ } else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
1248
+ const usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
1249
+ nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - usedLimitCount);
1250
+ } else {
1251
+ nextMaxUsageLimit = 1;
1252
+ }
1253
+ const nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
1254
+ if (nextSplitCount === 0) {
1255
+ processedItems.push({
1256
+ ...flatItem,
1257
+ _id: `${flatItem._id}_split_rest`,
1258
+ num: remainingNum,
1259
+ quantity: remainingNum,
1260
+ discount_list: [],
1261
+ processed: true
1262
+ });
1263
+ break;
1264
+ }
1265
+ for (let j = 0; j < nextSplitCount; j++) {
1266
+ const nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
1267
+ usedDiscounts.set(nextBundleDiscount.id, true);
1268
+ if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
1269
+ const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1270
+ usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1271
+ }
1272
+ const nextBundleDiscTypeForCount = nextBundleDiscount.tag || nextBundleDiscount.type;
1273
+ if (["discount_card", "product_discount_card"].includes(nextBundleDiscTypeForCount)) {
1274
+ const curLimitCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1275
+ usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curLimitCount + 1);
1276
+ }
1277
+ const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
1278
+ const nextDiscountedPrice = (0, import_utils.getDiscountAmount)(
1279
+ nextBundleDiscount,
1280
+ product.origin_total,
1281
+ product.origin_total
1282
+ );
1283
+ const nextBundleDiscAmount = new import_decimal.default(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
1284
+ const nextBundleDiscTypeStr = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
1285
+ const nextDiscountDetail = {
1286
+ amount: nextBundleDiscAmount,
1287
+ type: nextBundleDiscTypeStr,
1288
+ discount: {
1289
+ discount_card_type: (_G = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _G.discount_card_type,
1290
+ fixed_amount: nextBundleDiscAmount,
1291
+ resource_id: nextBundleDiscount.id,
1292
+ title: nextBundleDiscount.format_title,
1293
+ original_amount: product.origin_total,
1294
+ product_id: product.id,
1295
+ percent: nextBundleDiscount.par_value,
1296
+ discount_product_id: nextBundleDiscount.product_id
1297
+ },
1298
+ metadata: {
1299
+ custom_product_bundle_map_id: nextUniqueId,
1300
+ num: 1
1301
+ },
1302
+ _num: 1,
1303
+ config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config
1304
+ };
1305
+ const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1306
+ nextAppliedProducts.push(nextDiscountDetail);
1307
+ appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1308
+ processedItems.push({
1309
+ ...flatItem,
1310
+ _id: nextUniqueId,
1311
+ num: 1,
1312
+ quantity: 1,
1313
+ price: nextDiscountedPrice,
1314
+ total: nextDiscountedPrice,
1315
+ discount_list: [nextDiscountDetail],
1316
+ processed: true,
1317
+ _discountId: nextBundleDiscount.id
1318
+ });
1319
+ continueSplitIndex++;
1320
+ }
1321
+ remainingNum -= nextSplitCount;
1116
1322
  }
1117
1323
  } else {
1118
1324
  const currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
@@ -1152,9 +1358,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1152
1358
  amount: bundleActualDiscountAmount * (product.num || 1),
1153
1359
  type: currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag,
1154
1360
  discount: {
1155
- discount_card_type: (_C = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _C.discount_card_type,
1361
+ discount_card_type: (_H = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _H.discount_card_type,
1156
1362
  fixed_amount: bundleActualDiscountAmount,
1157
- discount_calculation_mode: (_D = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _D.discount_calculation_mode,
1363
+ discount_calculation_mode: (_I = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _I.discount_calculation_mode,
1158
1364
  resource_id: currentBundleDiscount.id,
1159
1365
  title: currentBundleDiscount.format_title,
1160
1366
  original_amount: product.original_price,
@@ -1171,7 +1377,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1171
1377
  ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
1172
1378
  },
1173
1379
  config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config,
1174
- _num: (product.num || 1) * (((_E = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _E.num) || 1)
1380
+ _num: (product.num || 1) * (((_J = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _J.num) || 1)
1175
1381
  };
1176
1382
  const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
1177
1383
  appliedProducts.push(discountDetail);
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 1 | 2 | 3 | 5 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -1776,10 +1776,12 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1776
1776
  currentStartTime: currentStartTime2,
1777
1777
  times
1778
1778
  }) {
1779
+ var _a4;
1779
1780
  const currentStart = (0, import_dayjs.default)(currentStartTime2);
1780
1781
  let earliestBlockStart;
1781
1782
  for (const time of times || []) {
1782
- for (const event of time.event_list || []) {
1783
+ const blockedTimes = (_a4 = time.event_list) == null ? void 0 : _a4.filter((event) => event.type !== "schedule_event");
1784
+ for (const event of blockedTimes || []) {
1783
1785
  const eventStart = (0, import_dayjs.default)(event.start_at);
1784
1786
  const eventEnd = (0, import_dayjs.default)(event.end_at);
1785
1787
  if (eventStart.isBefore(currentStart) && eventEnd.isAfter(currentStart)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.462",
4
+ "version": "0.0.464",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",