@pisell/pisellos 2.1.125 → 2.1.127

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.
Files changed (48) hide show
  1. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +8 -0
  2. package/dist/model/strategy/adapter/itemRule/adapter.js +52 -8
  3. package/dist/model/strategy/adapter/itemRule/examples.d.ts +15 -0
  4. package/dist/model/strategy/adapter/itemRule/examples.js +68 -1
  5. package/dist/model/strategy/adapter/itemRule/index.d.ts +1 -1
  6. package/dist/model/strategy/adapter/itemRule/index.js +1 -1
  7. package/dist/model/strategy/adapter/itemRule/type.d.ts +20 -1
  8. package/dist/modules/Order/index.d.ts +1 -1
  9. package/dist/modules/Order/index.js +6 -40
  10. package/dist/modules/Order/utils.d.ts +24 -0
  11. package/dist/modules/Order/utils.js +87 -11
  12. package/dist/modules/SalesSummary/types.d.ts +2 -1
  13. package/dist/modules/SalesSummary/utils.js +10 -10
  14. package/dist/modules/Schedule/utils.d.ts +1 -1
  15. package/dist/solution/ScanOrder/index.d.ts +5 -0
  16. package/dist/solution/ScanOrder/index.js +205 -64
  17. package/dist/solution/ScanOrder/types.d.ts +19 -5
  18. package/dist/solution/ScanOrder/utils.d.ts +15 -0
  19. package/dist/solution/ScanOrder/utils.js +142 -62
  20. package/dist/solution/VenueBooking/index.d.ts +4 -0
  21. package/dist/solution/VenueBooking/index.js +219 -141
  22. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  23. package/dist/solution/VenueBooking/utils/dateSummary.js +6 -4
  24. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +8 -0
  25. package/lib/model/strategy/adapter/itemRule/adapter.js +41 -2
  26. package/lib/model/strategy/adapter/itemRule/examples.d.ts +15 -0
  27. package/lib/model/strategy/adapter/itemRule/examples.js +47 -0
  28. package/lib/model/strategy/adapter/itemRule/index.d.ts +1 -1
  29. package/lib/model/strategy/adapter/itemRule/index.js +2 -0
  30. package/lib/model/strategy/adapter/itemRule/type.d.ts +20 -1
  31. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  32. package/lib/modules/Order/index.d.ts +1 -1
  33. package/lib/modules/Order/index.js +4 -37
  34. package/lib/modules/Order/utils.d.ts +24 -0
  35. package/lib/modules/Order/utils.js +65 -4
  36. package/lib/modules/SalesSummary/types.d.ts +2 -1
  37. package/lib/modules/SalesSummary/utils.js +2 -2
  38. package/lib/modules/Schedule/utils.d.ts +1 -1
  39. package/lib/solution/ScanOrder/index.d.ts +5 -0
  40. package/lib/solution/ScanOrder/index.js +94 -18
  41. package/lib/solution/ScanOrder/types.d.ts +19 -5
  42. package/lib/solution/ScanOrder/utils.d.ts +15 -0
  43. package/lib/solution/ScanOrder/utils.js +86 -19
  44. package/lib/solution/VenueBooking/index.d.ts +4 -0
  45. package/lib/solution/VenueBooking/index.js +85 -25
  46. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +1 -0
  47. package/lib/solution/VenueBooking/utils/dateSummary.js +13 -4
  48. package/package.json +1 -1
@@ -40,6 +40,7 @@ var import_types2 = require("../BookingByStep/types");
40
40
  var import_ProductList = require("../../modules/ProductList");
41
41
  var import_Date = require("../../modules/Date");
42
42
  var import_Schedule = require("../../modules/Schedule");
43
+ var import_utils2 = require("../../modules/Schedule/utils");
43
44
  var import_Quotation = require("../../modules/Quotation");
44
45
  var import_OpenData = require("../../modules/OpenData");
45
46
  var import_types3 = require("../../modules/Account/types");
@@ -49,7 +50,7 @@ var import_resource = require("./utils/resource");
49
50
  var import_timeSlot = require("./utils/timeSlot");
50
51
  var import_dateSummary = require("./utils/dateSummary");
51
52
  var import_slotMerge = require("./utils/slotMerge");
52
- var import_utils2 = require("../../modules/Order/utils");
53
+ var import_utils3 = require("../../modules/Order/utils");
53
54
  var import_Order = require("../../modules/Order");
54
55
  var import_types4 = require("../RegisterAndLogin/types");
55
56
  var import_decimal = __toESM(require("decimal.js"));
@@ -96,6 +97,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
96
97
  }
97
98
  };
98
99
  this.otherParams = {};
100
+ this.baseSlotConfig = { ...import_types.DEFAULT_SLOT_CONFIG };
99
101
  this.itemRuleEvaluator = new import_itemRule.ItemRuleEvaluator();
100
102
  this.itemRuleConfigs = [];
101
103
  this.itemRuleConfigsPromise = null;
@@ -301,10 +303,11 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
301
303
  this.store.status = "initializing";
302
304
  this.store.error = null;
303
305
  this.store.rawResourceData = [];
304
- this.store.slotConfig = {
306
+ this.baseSlotConfig = {
305
307
  ...import_types.DEFAULT_SLOT_CONFIG,
306
308
  ...((_b = options.otherParams) == null ? void 0 : _b.slotConfig) || {}
307
309
  };
310
+ this.store.slotConfig = { ...this.baseSlotConfig };
308
311
  this.otherParams = options.otherParams || {};
309
312
  this.cacheId = (_c = this.otherParams) == null ? void 0 : _c.cacheId;
310
313
  this.itemRuleRuntimeConfig = ((_d = this.otherParams) == null ? void 0 : _d.venueBookingItemRule) || ((_e = this.otherParams) == null ? void 0 : _e.itemRule) || {};
@@ -645,27 +648,87 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
645
648
  }
646
649
  }
647
650
  // ─── 日期概览 & 时间槽矩阵(纯计算,不发请求) ───
651
+ getOperatingHoursScheduleIds() {
652
+ var _a, _b;
653
+ const openData = this.otherParams.openData || ((_b = (_a = this.store.openData) == null ? void 0 : _a.getOpenData) == null ? void 0 : _b.call(_a)) || null;
654
+ const rawIds = openData == null ? void 0 : openData["availability.operating_hours"];
655
+ if (!Array.isArray(rawIds))
656
+ return [];
657
+ return [...new Set(
658
+ rawIds.map((id) => Number(id)).filter((id) => Number.isFinite(id) && id > 0).map((id) => Math.floor(id))
659
+ )];
660
+ }
661
+ resolveSlotConfigForDate(date) {
662
+ var _a;
663
+ const nextSlotConfig = { ...this.baseSlotConfig };
664
+ if (!date || !this.store.schedule)
665
+ return nextSlotConfig;
666
+ const operatingHoursScheduleIds = this.getOperatingHoursScheduleIds();
667
+ if (!operatingHoursScheduleIds.length)
668
+ return nextSlotConfig;
669
+ const scheduleList = this.store.schedule.getScheduleListByIds(
670
+ operatingHoursScheduleIds
671
+ );
672
+ if (!scheduleList.length)
673
+ return nextSlotConfig;
674
+ const timeRangeMap = (0, import_utils2.calcMinTimeMaxTimeBySchedules)(
675
+ scheduleList,
676
+ void 0,
677
+ date
678
+ );
679
+ let earliestStart = null;
680
+ let latestEnd = null;
681
+ for (const schedule of scheduleList) {
682
+ const dateRangeList = ((_a = timeRangeMap == null ? void 0 : timeRangeMap[schedule.id]) == null ? void 0 : _a.dateRangeFormat) || [];
683
+ for (const range of dateRangeList) {
684
+ const start = (0, import_dayjs.default)(range == null ? void 0 : range.start);
685
+ const end = (0, import_dayjs.default)(range == null ? void 0 : range.end);
686
+ if (!start.isValid() || !end.isValid())
687
+ continue;
688
+ if (!earliestStart || start.isBefore(earliestStart)) {
689
+ earliestStart = start;
690
+ }
691
+ if (!latestEnd || end.isAfter(latestEnd)) {
692
+ latestEnd = end;
693
+ }
694
+ }
695
+ }
696
+ if (!earliestStart || !latestEnd)
697
+ return nextSlotConfig;
698
+ return {
699
+ ...nextSlotConfig,
700
+ businessStartTime: earliestStart.format("HH:mm"),
701
+ businessEndTime: latestEnd.format("HH:mm")
702
+ };
703
+ }
704
+ syncOperatingHoursToSlotConfig(date) {
705
+ const resolvedSlotConfig = this.resolveSlotConfigForDate(date);
706
+ this.store.slotConfig = resolvedSlotConfig;
707
+ return resolvedSlotConfig;
708
+ }
648
709
  getDateRangeSummary(params) {
649
710
  return (0, import_dateSummary.buildDateRangeSummary)({
650
711
  startDate: params.startDate,
651
712
  endDate: params.endDate,
652
- config: this.store.slotConfig,
713
+ config: this.baseSlotConfig,
653
714
  rawResources: this.store.rawResourceData,
654
715
  resourceProductMap: this.resourceProductMap,
655
- quotationModule: this.store.quotation
716
+ quotationModule: this.store.quotation,
717
+ resolveConfig: (date) => this.resolveSlotConfigForDate(date)
656
718
  });
657
719
  }
658
720
  getTimeSlotGrid(date) {
721
+ const resolvedSlotConfig = this.syncOperatingHoursToSlotConfig(date);
659
722
  let quotationPriceMap;
660
723
  if (this.store.quotation) {
661
724
  const productIds = [...new Set([...this.resourceProductMap.values()].map((m) => m.productId))];
662
- const timeLabels = (0, import_timeSlot.generateTimeLabels)(this.store.slotConfig);
725
+ const timeLabels = (0, import_timeSlot.generateTimeLabels)(resolvedSlotConfig);
663
726
  const timePoints = timeLabels.map((label) => `${date} ${label}`);
664
727
  quotationPriceMap = this.store.quotation.buildProductPriceMap({ productIds, timePoints });
665
728
  }
666
729
  return (0, import_timeSlot.buildTimeSlotGrid)({
667
730
  date,
668
- config: this.store.slotConfig,
731
+ config: resolvedSlotConfig,
669
732
  rawResources: this.store.rawResourceData,
670
733
  resourceProductMap: this.resourceProductMap,
671
734
  quotationPriceMap
@@ -800,7 +863,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
800
863
  for (let i = 0; i < merged.length; i++) {
801
864
  const group = merged[i];
802
865
  const identityKey = (0, import_slotMerge.buildVenueIdentityKey)(resourceId, i);
803
- const bookingUuid = (0, import_utils2.createUuidV4)();
866
+ const bookingUuid = (0, import_utils3.createUuidV4)();
804
867
  const startMoment = (0, import_dayjs.default)(group.startTime, "YYYY-MM-DD HH:mm");
805
868
  const endMoment = (0, import_dayjs.default)(group.endTime, "YYYY-MM-DD HH:mm");
806
869
  const duration = endMoment.diff(startMoment, "minute");
@@ -813,7 +876,6 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
813
876
  num: 1,
814
877
  selling_price: group.totalPrice,
815
878
  original_price: group.totalPrice,
816
- payment_price: group.totalPrice,
817
879
  is_charge_tax: (venueProduct == null ? void 0 : venueProduct.is_charge_tax) ?? 0,
818
880
  metadata: {
819
881
  venue_booking: true,
@@ -892,10 +954,13 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
892
954
  }
893
955
  // ─── 配置 ───
894
956
  setSlotConfig(config) {
895
- this.store.slotConfig = {
896
- ...this.store.slotConfig,
957
+ this.baseSlotConfig = {
958
+ ...this.baseSlotConfig,
897
959
  ...config
898
960
  };
961
+ this.store.slotConfig = {
962
+ ...this.baseSlotConfig
963
+ };
899
964
  }
900
965
  getSlotConfig() {
901
966
  return { ...this.store.slotConfig };
@@ -986,7 +1051,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
986
1051
  const merged = (0, import_slotMerge.mergeConsecutiveSlots)(updatedSlots);
987
1052
  if (merged.length === 1) {
988
1053
  product.selling_price = merged[0].totalPrice;
989
- product.payment_price = merged[0].totalPrice;
1054
+ product.original_price = merged[0].totalPrice;
990
1055
  product.metadata.price_breakdown = (0, import_slotMerge.buildPriceBreakdown)({
991
1056
  group: merged[0],
992
1057
  productId: mapping.productId,
@@ -1001,7 +1066,7 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1001
1066
  });
1002
1067
  if (quotationPrice !== null) {
1003
1068
  product.selling_price = quotationPrice;
1004
- product.payment_price = quotationPrice;
1069
+ product.original_price = quotationPrice;
1005
1070
  }
1006
1071
  }
1007
1072
  }
@@ -1096,15 +1161,14 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1096
1161
  return rid != null && selectedResourceIds.has(rid);
1097
1162
  });
1098
1163
  if (product.discount_list.length < before) {
1099
- const totalDiscountAmount = product.discount_list.reduce(
1164
+ const totalPerUnitDiscount = product.discount_list.reduce(
1100
1165
  (sum, pd) => sum + (pd.amount || 0),
1101
1166
  0
1102
1167
  );
1103
- const newPaymentPrice = new import_decimal.default(product.selling_price || 0).minus(totalDiscountAmount).toNumber();
1104
- const paymentStr = (0, import_utils.toPriceString)(newPaymentPrice);
1105
- product.payment_price = paymentStr;
1168
+ const newSellingPrice = new import_decimal.default(product.original_price || product.selling_price || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1169
+ product.selling_price = newSellingPrice;
1106
1170
  if (product.metadata) {
1107
- product.metadata.main_product_selling_price = paymentStr;
1171
+ product.metadata.main_product_selling_price = newSellingPrice;
1108
1172
  }
1109
1173
  }
1110
1174
  }
@@ -1201,10 +1265,9 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1201
1265
  });
1202
1266
  if (quotationPrice !== null) {
1203
1267
  product.selling_price = quotationPrice;
1204
- if (product.original_price == null) {
1205
- product.original_price = quotationPrice;
1206
- }
1207
- product.payment_price = quotationPrice;
1268
+ product.original_price = quotationPrice;
1269
+ } else if (product.selling_price != null) {
1270
+ product.original_price = product.selling_price;
1208
1271
  }
1209
1272
  }
1210
1273
  const products = await this.store.order.addProductToOrder(product);
@@ -1449,16 +1512,13 @@ var _VenueBookingImpl = class extends import_BaseModule.BaseModule {
1449
1512
  });
1450
1513
  if (productIndex === -1) {
1451
1514
  const sellingPrice = (0, import_utils.toPriceString)((sourceItem == null ? void 0 : sourceItem.price) ?? (sourceItem == null ? void 0 : sourceItem.selling_price), "0.00");
1452
- const originalPrice = (0, import_utils.toPriceString)((sourceItem == null ? void 0 : sourceItem.original_price) ?? (sourceItem == null ? void 0 : sourceItem.price) ?? sellingPrice, sellingPrice);
1453
- const paymentPrice = (0, import_utils.toPriceString)((sourceItem == null ? void 0 : sourceItem.payment_price) ?? (sourceItem == null ? void 0 : sourceItem.price) ?? sellingPrice, sellingPrice);
1454
1515
  tempOrder.products.push(
1455
1516
  (0, import_utils.normalizeOrderProduct)({
1456
1517
  product_id: productId,
1457
1518
  product_variant_id: productVariantId,
1458
1519
  num: targetQuantity,
1459
1520
  selling_price: sellingPrice,
1460
- original_price: originalPrice,
1461
- payment_price: paymentPrice,
1521
+ original_price: sellingPrice,
1462
1522
  metadata: { item_rule_prefill: true, item_rule_id: prefillItem.ruleId },
1463
1523
  _origin: { ...sourceItem || {}, item_rule_prefill: true, item_rule_id: prefillItem.ruleId }
1464
1524
  })
@@ -7,4 +7,5 @@ export declare function buildDateRangeSummary(params: {
7
7
  rawResources: VenueResourceRawData[];
8
8
  resourceProductMap: Map<number | string, ResourceProductMapping>;
9
9
  quotationModule?: QuotationModule;
10
+ resolveConfig?: (date: string) => VenueBookingSlotConfig;
10
11
  }): VenueDateSummaryItem[];
@@ -35,22 +35,31 @@ module.exports = __toCommonJS(dateSummary_exports);
35
35
  var import_dayjs = __toESM(require("dayjs"));
36
36
  var import_timeSlot = require("./timeSlot");
37
37
  function buildDateRangeSummary(params) {
38
- const { startDate, endDate, config, rawResources, resourceProductMap, quotationModule } = params;
38
+ const {
39
+ startDate,
40
+ endDate,
41
+ config,
42
+ rawResources,
43
+ resourceProductMap,
44
+ quotationModule,
45
+ resolveConfig
46
+ } = params;
39
47
  const result = [];
40
48
  const productIds = quotationModule ? [...new Set([...resourceProductMap.values()].map((m) => m.productId))] : [];
41
49
  let cursor = (0, import_dayjs.default)(startDate);
42
50
  const end = (0, import_dayjs.default)(endDate);
43
51
  while (!cursor.isAfter(end)) {
44
52
  const date = cursor.format("YYYY-MM-DD");
53
+ const effectiveConfig = (resolveConfig == null ? void 0 : resolveConfig(date)) || config;
45
54
  let quotationPriceMap;
46
55
  if (quotationModule && productIds.length) {
47
- const timeLabels = (0, import_timeSlot.generateTimeLabels)(config);
56
+ const timeLabels = (0, import_timeSlot.generateTimeLabels)(effectiveConfig);
48
57
  const timePoints = timeLabels.map((label) => `${date} ${label}`);
49
58
  quotationPriceMap = quotationModule.buildProductPriceMap({ productIds, timePoints });
50
59
  }
51
60
  const grid = (0, import_timeSlot.buildTimeSlotGrid)({
52
61
  date,
53
- config,
62
+ config: effectiveConfig,
54
63
  rawResources,
55
64
  resourceProductMap,
56
65
  quotationPriceMap
@@ -79,7 +88,7 @@ function buildDateRangeSummary(params) {
79
88
  status = "unavailable";
80
89
  } else if (availableSlots === 0) {
81
90
  status = "sold_out";
82
- } else if ((totalSlots - availableSlots) / totalSlots >= config.fewLeftThreshold) {
91
+ } else if ((totalSlots - availableSlots) / totalSlots >= effectiveConfig.fewLeftThreshold) {
83
92
  status = "few_left";
84
93
  } else {
85
94
  status = "available";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.125",
4
+ "version": "2.1.127",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",