@pisell/pisellos 0.0.320 → 0.0.324

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 (86) hide show
  1. package/dist/effects/index.d.ts +2 -2
  2. package/dist/modules/Customer/types.d.ts +1 -1
  3. package/dist/modules/Discount/index.d.ts +2 -0
  4. package/dist/modules/Discount/index.js +67 -35
  5. package/dist/modules/Discount/types.d.ts +5 -0
  6. package/dist/modules/Payment/types.d.ts +7 -7
  7. package/dist/modules/ProductList/index.js +2 -1
  8. package/dist/modules/Rules/types.d.ts +1 -1
  9. package/dist/modules/Schedule/type.d.ts +7 -7
  10. package/dist/modules/Schedule/types.d.ts +9 -9
  11. package/dist/solution/BookingByStep/index.d.ts +1 -1
  12. package/dist/solution/BookingByStep/utils/resources.d.ts +1 -1
  13. package/dist/solution/BookingTicket/index.d.ts +1 -1
  14. package/dist/solution/ShopDiscount/index.d.ts +4 -0
  15. package/dist/solution/ShopDiscount/index.js +190 -101
  16. package/dist/solution/ShopDiscount/types.d.ts +5 -2
  17. package/dist/solution/ShopDiscount/utils.d.ts +48 -0
  18. package/dist/solution/ShopDiscount/utils.js +281 -0
  19. package/dist/types/index.d.ts +1 -1
  20. package/dist/utils/task.d.ts +2 -2
  21. package/dist/utils/watch.d.ts +2 -2
  22. package/lib/core/index.js +27 -28
  23. package/lib/effects/index.d.ts +2 -2
  24. package/lib/effects/index.js +3 -7
  25. package/lib/modules/Account/index.js +9 -10
  26. package/lib/modules/AccountList/index.js +14 -11
  27. package/lib/modules/BaseModule.js +6 -3
  28. package/lib/modules/Cart/index.js +14 -9
  29. package/lib/modules/Cart/utils/cartProduct.js +3 -6
  30. package/lib/modules/Customer/constants.js +1 -1
  31. package/lib/modules/Customer/index.js +18 -15
  32. package/lib/modules/Customer/types.d.ts +1 -1
  33. package/lib/modules/Date/index.js +10 -6
  34. package/lib/modules/Date/types.js +1 -0
  35. package/lib/modules/Discount/index.d.ts +2 -0
  36. package/lib/modules/Discount/index.js +28 -9
  37. package/lib/modules/Discount/types.d.ts +5 -0
  38. package/lib/modules/Guests/index.js +10 -15
  39. package/lib/modules/Order/index.js +11 -9
  40. package/lib/modules/Payment/cash.js +1 -1
  41. package/lib/modules/Payment/cashRecommendationAlgorithm.js +1 -1
  42. package/lib/modules/Payment/eftpos.js +1 -1
  43. package/lib/modules/Payment/index.js +80 -69
  44. package/lib/modules/Payment/types.d.ts +7 -7
  45. package/lib/modules/Payment/utils.js +3 -6
  46. package/lib/modules/Payment/walletpass.js +31 -31
  47. package/lib/modules/Product/index.js +6 -5
  48. package/lib/modules/ProductList/index.js +7 -4
  49. package/lib/modules/Resource/index.js +8 -12
  50. package/lib/modules/Rules/index.js +12 -17
  51. package/lib/modules/Rules/types.d.ts +1 -1
  52. package/lib/modules/Schedule/index.js +8 -5
  53. package/lib/modules/Schedule/type.d.ts +7 -7
  54. package/lib/modules/Schedule/types.d.ts +9 -9
  55. package/lib/modules/Schedule/utils.js +2 -4
  56. package/lib/modules/Step/index.js +7 -4
  57. package/lib/modules/Summary/index.js +9 -4
  58. package/lib/plugins/request.js +34 -33
  59. package/lib/plugins/window.js +101 -113
  60. package/lib/solution/BookingByStep/index.d.ts +1 -1
  61. package/lib/solution/BookingByStep/index.js +70 -104
  62. package/lib/solution/BookingByStep/utils/capacity.js +10 -15
  63. package/lib/solution/BookingByStep/utils/resources.d.ts +1 -1
  64. package/lib/solution/BookingByStep/utils/resources.js +4 -8
  65. package/lib/solution/BookingByStep/utils/stock.js +3 -6
  66. package/lib/solution/BookingByStep/utils/timeslots.js +24 -27
  67. package/lib/solution/BookingTicket/index.d.ts +1 -1
  68. package/lib/solution/BookingTicket/index.js +19 -14
  69. package/lib/solution/BookingTicket/utils/scan/cloudSearch.js +3 -3
  70. package/lib/solution/BookingTicket/utils/scan/handleScan.js +6 -6
  71. package/lib/solution/BookingTicket/utils/scan/index.js +3 -1
  72. package/lib/solution/BookingTicket/utils/scan/scanCache.js +10 -9
  73. package/lib/solution/BuyTickets/index.js +15 -15
  74. package/lib/solution/Checkout/index.js +206 -199
  75. package/lib/solution/Checkout/utils/index.js +18 -22
  76. package/lib/solution/ShopDiscount/index.d.ts +4 -0
  77. package/lib/solution/ShopDiscount/index.js +59 -16
  78. package/lib/solution/ShopDiscount/types.d.ts +5 -2
  79. package/lib/solution/ShopDiscount/utils.d.ts +48 -0
  80. package/lib/solution/ShopDiscount/utils.js +172 -0
  81. package/lib/types/index.d.ts +1 -1
  82. package/lib/utils/task.d.ts +2 -2
  83. package/lib/utils/task.js +3 -3
  84. package/lib/utils/watch.d.ts +2 -2
  85. package/lib/utils/watch.js +5 -7
  86. package/package.json +1 -1
@@ -48,26 +48,26 @@ var import_types = require("../../../modules/Payment/types");
48
48
  function validateCheckoutData(params) {
49
49
  const errors = [];
50
50
  if (!params.cartItems || params.cartItems.length === 0) {
51
- errors.push("购物车不能为空");
51
+ errors.push("\u8D2D\u7269\u8F66\u4E0D\u80FD\u4E3A\u7A7A");
52
52
  }
53
53
  if (params.cartItems) {
54
54
  params.cartItems.forEach((item, index) => {
55
55
  if (!item.id) {
56
- errors.push(`购物车商品 ${index + 1} 缺少商品ID`);
56
+ errors.push(`\u8D2D\u7269\u8F66\u5546\u54C1 ${index + 1} \u7F3A\u5C11\u5546\u54C1ID`);
57
57
  }
58
58
  if (!item.price || parseFloat(String(item.price)) < 0) {
59
- errors.push(`购物车商品 ${index + 1} 价格无效`);
59
+ errors.push(`\u8D2D\u7269\u8F66\u5546\u54C1 ${index + 1} \u4EF7\u683C\u65E0\u6548`);
60
60
  }
61
61
  if (!item.num || item.num <= 0) {
62
- errors.push(`购物车商品 ${index + 1} 数量无效`);
62
+ errors.push(`\u8D2D\u7269\u8F66\u5546\u54C1 ${index + 1} \u6570\u91CF\u65E0\u6548`);
63
63
  }
64
64
  });
65
65
  }
66
66
  if (params.orderType && !["virtual", "appointment_booking"].includes(params.orderType)) {
67
- errors.push("订单类型无效,必须是 virtual 或 appointment_booking");
67
+ errors.push("\u8BA2\u5355\u7C7B\u578B\u65E0\u6548\uFF0C\u5FC5\u987B\u662F virtual \u6216 appointment_booking");
68
68
  }
69
69
  if (params.platform && !["pc", "h5"].includes(params.platform)) {
70
- errors.push("平台类型无效,必须是 pc 或 h5");
70
+ errors.push("\u5E73\u53F0\u7C7B\u578B\u65E0\u6548\uFF0C\u5FC5\u987B\u662F pc \u6216 h5");
71
71
  }
72
72
  return {
73
73
  valid: errors.length === 0,
@@ -84,8 +84,7 @@ function createCheckoutError(type, message, details) {
84
84
  }
85
85
  function formatAmount(amount) {
86
86
  const numAmount = typeof amount === "string" ? parseFloat(amount) : amount;
87
- if (isNaN(numAmount))
88
- return "0.00";
87
+ if (isNaN(numAmount)) return "0.00";
89
88
  return numAmount.toFixed(2);
90
89
  }
91
90
  function validateAmount(amount) {
@@ -165,12 +164,9 @@ async function retry(fn, maxAttempts = 3, delay = 1e3) {
165
164
  throw lastError;
166
165
  }
167
166
  function isEmpty(obj) {
168
- if (obj == null)
169
- return true;
170
- if (Array.isArray(obj) || typeof obj === "string")
171
- return obj.length === 0;
172
- if (typeof obj === "object")
173
- return Object.keys(obj).length === 0;
167
+ if (obj == null) return true;
168
+ if (Array.isArray(obj) || typeof obj === "string") return obj.length === 0;
169
+ if (typeof obj === "object") return Object.keys(obj).length === 0;
174
170
  return false;
175
171
  }
176
172
  function getErrorMessage(error) {
@@ -183,7 +179,7 @@ function getErrorMessage(error) {
183
179
  if (error && typeof error === "object" && "message" in error) {
184
180
  return String(error.message);
185
181
  }
186
- return "未知错误";
182
+ return "\u672A\u77E5\u9519\u8BEF";
187
183
  }
188
184
  function isProduction() {
189
185
  return process.env.NODE_ENV === "production";
@@ -208,24 +204,24 @@ function validateLocalOrderData(orderData) {
208
204
  var _a;
209
205
  const errors = [];
210
206
  if (!orderData.type) {
211
- errors.push("订单类型不能为空");
207
+ errors.push("\u8BA2\u5355\u7C7B\u578B\u4E0D\u80FD\u4E3A\u7A7A");
212
208
  }
213
209
  if (!orderData.platform) {
214
- errors.push("平台信息不能为空");
210
+ errors.push("\u5E73\u53F0\u4FE1\u606F\u4E0D\u80FD\u4E3A\u7A7A");
215
211
  }
216
212
  if ((!orderData.bookings || orderData.bookings.length === 0) && !((_a = orderData == null ? void 0 : orderData.relation_products) == null ? void 0 : _a.length)) {
217
- errors.push("预订信息不能为空");
213
+ errors.push("\u9884\u8BA2\u4FE1\u606F\u4E0D\u80FD\u4E3A\u7A7A");
218
214
  }
219
215
  if (orderData.bookings) {
220
216
  orderData.bookings.forEach((booking, index) => {
221
217
  if (!booking.product || !booking.product.product_id) {
222
- errors.push(`预订项 ${index + 1} 缺少商品信息`);
218
+ errors.push(`\u9884\u8BA2\u9879 ${index + 1} \u7F3A\u5C11\u5546\u54C1\u4FE1\u606F`);
223
219
  }
224
220
  if (!booking.start_date) {
225
- errors.push(`预订项 ${index + 1} 缺少开始日期`);
221
+ errors.push(`\u9884\u8BA2\u9879 ${index + 1} \u7F3A\u5C11\u5F00\u59CB\u65E5\u671F`);
226
222
  }
227
223
  if (!booking.start_time) {
228
- errors.push(`预订项 ${index + 1} 缺少开始时间`);
224
+ errors.push(`\u9884\u8BA2\u9879 ${index + 1} \u7F3A\u5C11\u5F00\u59CB\u65F6\u95F4`);
229
225
  }
230
226
  });
231
227
  }
@@ -288,7 +284,7 @@ function extractAmountFromCartSummary(cartSummary) {
288
284
  break;
289
285
  }
290
286
  });
291
- console.log("[Checkout] 从购物车小计提取金额信息:", {
287
+ console.log("[Checkout] \u4ECE\u8D2D\u7269\u8F66\u5C0F\u8BA1\u63D0\u53D6\u91D1\u989D\u4FE1\u606F:", {
292
288
  totalAmount: result.totalAmount,
293
289
  subTotal: result.subTotal,
294
290
  taxAmount: result.taxAmount,
@@ -18,6 +18,10 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
18
18
  private initializePlugins;
19
19
  private registerDependentModules;
20
20
  private registerEventListeners;
21
+ setBookingTime(bookingTime: string | null): Promise<void>;
22
+ getCurrentBookingTime(): string | null;
23
+ private filterDiscountListByBookingTime;
24
+ private updateFilteredDiscountList;
21
25
  setCustomer(customer: Customer): Promise<void>;
22
26
  calcDiscount(productList: Record<string, any>[], options?: SetDiscountSelectedParams): {
23
27
  productList: Record<string, any>[];
@@ -37,21 +37,28 @@ var import_BaseModule = require("../../modules/BaseModule");
37
37
  var import_types = require("./types");
38
38
  var import_Discount = require("../../modules/Discount");
39
39
  var import_Rules = require("../../modules/Rules");
40
+ var import_utils = require("./utils");
40
41
  var import_decimal = __toESM(require("decimal.js"));
41
42
  var import_lodash_es = require("lodash-es");
42
43
  var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
44
+ defaultName = "shopDiscount";
45
+ defaultVersion = "1.0.0";
46
+ isSolution = true;
47
+ request;
48
+ window;
49
+ store;
50
+ options = {};
51
+ hooks;
43
52
  constructor(name, version) {
44
53
  super(name, version);
45
- this.defaultName = "shopDiscount";
46
- this.defaultVersion = "1.0.0";
47
- this.isSolution = true;
48
- this.options = {};
49
54
  this.store = {
50
55
  customer: null,
51
56
  productList: [],
52
57
  discount: null,
53
58
  rules: null,
54
- originalDiscountList: []
59
+ originalDiscountList: [],
60
+ currentBookingTime: "",
61
+ filteredDiscountList: []
55
62
  };
56
63
  }
57
64
  // =========== 生命周期方法 ===========
@@ -61,7 +68,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
61
68
  this.options = options;
62
69
  this.store = { ...this.store, ...options.store || {} };
63
70
  this.hooks = (_b = (_a = options.otherParams) == null ? void 0 : _a.rules) == null ? void 0 : _b.hooks;
64
- console.log("[ShopDiscount] 初始化完成");
71
+ console.log("[ShopDiscount] \u521D\u59CB\u5316\u5B8C\u6210");
65
72
  this.initializePlugins();
66
73
  this.registerDependentModules();
67
74
  this.registerEventListeners();
@@ -74,7 +81,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
74
81
  (_b = this.store.rules) == null ? void 0 : _b.destroy();
75
82
  this.core.effects.offByModuleDestroy(this.name);
76
83
  await this.core.effects.emit(import_types.ShopDiscountHooks.onDestroy, {});
77
- console.log("[ShopDiscount] 已销毁");
84
+ console.log("[ShopDiscount] \u5DF2\u9500\u6BC1");
78
85
  }
79
86
  async clear() {
80
87
  var _a, _b;
@@ -89,10 +96,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
89
96
  this.request = this.core.getPlugin("request");
90
97
  this.window = this.core.getPlugin("window");
91
98
  if (!this.request) {
92
- throw new Error("ShopDiscount需要 request 插件支持");
99
+ throw new Error("ShopDiscount\u9700\u8981 request \u63D2\u4EF6\u652F\u6301");
93
100
  }
94
101
  if (!this.window) {
95
- throw new Error("ShopDiscount需要 window 插件支持");
102
+ throw new Error("ShopDiscount\u9700\u8981 window \u63D2\u4EF6\u652F\u6301");
96
103
  }
97
104
  }
98
105
  registerDependentModules() {
@@ -140,6 +147,39 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
140
147
  );
141
148
  }
142
149
  // =========== 公共 API ===========
150
+ // 设置预约时间
151
+ async setBookingTime(bookingTime) {
152
+ if (this.store.currentBookingTime !== bookingTime) {
153
+ this.store.currentBookingTime = bookingTime;
154
+ await this.updateFilteredDiscountList();
155
+ }
156
+ }
157
+ // 获取当前预约时间
158
+ getCurrentBookingTime() {
159
+ return this.store.currentBookingTime;
160
+ }
161
+ // 根据预约时间过滤优惠券列表
162
+ filterDiscountListByBookingTime(discountList, bookingTime) {
163
+ if ((0, import_utils.isAllNormalProduct)(this.store.productList || [])) {
164
+ return discountList;
165
+ }
166
+ return (0, import_utils.filterDiscountListByBookingTime)(discountList, bookingTime);
167
+ }
168
+ // 更新过滤后的优惠券列表
169
+ async updateFilteredDiscountList() {
170
+ var _a;
171
+ const originalList = this.store.originalDiscountList;
172
+ const filteredList = this.filterDiscountListByBookingTime(originalList, this.store.currentBookingTime);
173
+ this.store.filteredDiscountList = filteredList;
174
+ this.setDiscountList(filteredList);
175
+ if ((_a = this.store.productList) == null ? void 0 : _a.length) {
176
+ const result = this.calcDiscount(this.store.productList);
177
+ await this.core.effects.emit(
178
+ import_types.ShopDiscountHooks.onLoadPrepareCalcResult,
179
+ result
180
+ );
181
+ }
182
+ }
143
183
  // 设置客户
144
184
  async setCustomer(customer) {
145
185
  var _a;
@@ -264,7 +304,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
264
304
  discountList: newDiscountList || this.getDiscountList()
265
305
  };
266
306
  } catch (error) {
267
- console.error("[ShopDiscount] 扫码出错:", error);
307
+ console.error("[ShopDiscount] \u626B\u7801\u51FA\u9519:", error);
268
308
  return {
269
309
  type: "clientCalc",
270
310
  isAvailable: false,
@@ -395,7 +435,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
395
435
  );
396
436
  }
397
437
  } catch (error) {
398
- console.error("[ShopDiscount] 获取客户钱包信息出错:", error);
438
+ console.error("[ShopDiscount] \u83B7\u53D6\u5BA2\u6237\u94B1\u5305\u4FE1\u606F\u51FA\u9519:", error);
399
439
  }
400
440
  }
401
441
  async bestDiscount(cb) {
@@ -417,7 +457,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
417
457
  }
418
458
  // 加载准备配置
419
459
  async loadPrepareConfig(params) {
420
- var _a, _b, _c, _d;
460
+ var _a, _b, _c, _d, _e;
421
461
  try {
422
462
  const customerId = params.customerId || ((_a = this.getCustomer()) == null ? void 0 : _a.id);
423
463
  const goodPassList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
@@ -433,8 +473,11 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
433
473
  const newGoodPassList = goodPassList == null ? void 0 : goodPassList.filter((n) => !scanDiscountIds.includes(n.id));
434
474
  const newDiscountList = [...scanDiscount, ...newGoodPassList || []];
435
475
  this.store.originalDiscountList = newDiscountList;
436
- this.setDiscountList(newDiscountList || []);
437
- if ((_d = this.store.productList) == null ? void 0 : _d.length) {
476
+ await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(newDiscountList));
477
+ const filteredDiscountList = this.filterDiscountListByBookingTime(newDiscountList, this.store.currentBookingTime);
478
+ this.store.filteredDiscountList = filteredDiscountList;
479
+ this.setDiscountList(filteredDiscountList || []);
480
+ if ((_e = this.store.productList) == null ? void 0 : _e.length) {
438
481
  const result = this.calcDiscount(this.store.productList);
439
482
  await this.core.effects.emit(
440
483
  import_types.ShopDiscountHooks.onLoadPrepareCalcResult,
@@ -443,10 +486,10 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
443
486
  }
444
487
  await this.core.effects.emit(
445
488
  import_types.ShopDiscountHooks.onLoadDiscountList,
446
- newDiscountList
489
+ filteredDiscountList
447
490
  );
448
491
  } catch (error) {
449
- console.error("[ShopDiscount] 加载准备配置出错:", error);
492
+ console.error("[ShopDiscount] \u52A0\u8F7D\u51C6\u5907\u914D\u7F6E\u51FA\u9519:", error);
450
493
  }
451
494
  }
452
495
  };
@@ -1,5 +1,6 @@
1
- import { DiscountModule, Discount } from '../../modules/Discount';
1
+ import { DiscountModule } from '../../modules/Discount';
2
2
  import { RulesModule } from '../../modules/Rules';
3
+ import { Discount } from "../../modules/Discount/types";
3
4
  export declare enum ShopDiscountHooks {
4
5
  onInited = "shopDiscount:onInited",
5
6
  onDestroy = "shopDiscount:onDestroy",
@@ -10,7 +11,7 @@ export declare enum ShopDiscountHooks {
10
11
  onRulesListChange = "shopDiscount:onRulesListChange",
11
12
  onLoadPrepareCalcResult = "shopDiscount:onLoadPrepareCalcResult"
12
13
  }
13
- export type Customer = {
14
+ export declare type Customer = {
14
15
  id: string | number;
15
16
  name: string;
16
17
  email: string;
@@ -23,6 +24,8 @@ export interface ShopDiscountState {
23
24
  rules: RulesModule | null;
24
25
  productList: Record<string, any>[];
25
26
  originalDiscountList: Discount[];
27
+ currentBookingTime: string | null;
28
+ filteredDiscountList: Discount[];
26
29
  }
27
30
  export interface SetDiscountSelectedParams {
28
31
  discountId: number;
@@ -1,5 +1,7 @@
1
1
  import { Discount } from "../../modules/Discount/types";
2
2
  export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
3
+ export declare const isNormalProductByDurationSchedule: (item: any) => boolean;
4
+ export declare const isAllNormalProduct: (items: any[]) => boolean;
3
5
  /**
4
6
  * 获取折扣金额 基于折扣卡类型计算
5
7
  * 商品券:直接返回商品价格
@@ -10,3 +12,49 @@ export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
10
12
  * @returns
11
13
  */
12
14
  export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
15
+ export interface ScheduleItem {
16
+ id: number;
17
+ name: string | {
18
+ [key: string]: string;
19
+ };
20
+ type: 'standard' | 'time-slots' | 'designation';
21
+ start_time: string | null;
22
+ end_time: string | null;
23
+ repeat_type: 'none' | 'daily' | 'weekly';
24
+ repeat_rule: {
25
+ end: {
26
+ type: 'never' | 'date' | 'occurrence';
27
+ end_date: string | null;
28
+ occurrence: number | null;
29
+ };
30
+ frequency: number;
31
+ excluded_date: Array<{
32
+ start: string;
33
+ end: string;
34
+ }>;
35
+ included_date: Array<{
36
+ start: string;
37
+ end: string;
38
+ }>;
39
+ frequency_date: number[];
40
+ } | null;
41
+ designation: Array<{
42
+ start_date: string;
43
+ start_time: string;
44
+ end_date: string;
45
+ end_time: string;
46
+ }> | null;
47
+ is_all: number;
48
+ time_slot: Array<{
49
+ start_time: string;
50
+ end_time: string;
51
+ }>;
52
+ }
53
+ export declare const getDateIsInSchedule: (dateTime: string, scheduleList: ScheduleItem[]) => boolean;
54
+ /**
55
+ * 根据预约时间过滤优惠券列表
56
+ * @param discountList 优惠券列表
57
+ * @param bookingTime 预约时间 (格式: YYYY-MM-DD HH:mm:ss)
58
+ * @returns 过滤后的优惠券列表
59
+ */
60
+ export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
@@ -29,15 +29,27 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/solution/ShopDiscount/utils.ts
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
+ filterDiscountListByBookingTime: () => filterDiscountListByBookingTime,
33
+ getDateIsInSchedule: () => getDateIsInSchedule,
32
34
  getDiscountAmount: () => getDiscountAmount,
35
+ isAllNormalProduct: () => isAllNormalProduct,
36
+ isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
33
37
  uniqueById: () => uniqueById
34
38
  });
35
39
  module.exports = __toCommonJS(utils_exports);
36
40
  var import_decimal = __toESM(require("decimal.js"));
41
+ var import_dayjs = __toESM(require("dayjs"));
37
42
  var uniqueById = (arr, key = "id") => {
38
43
  const seen = /* @__PURE__ */ new Set();
39
44
  return arr.filter((item) => !seen.has(item[key]) && seen.add(item[key]));
40
45
  };
46
+ var isNormalProductByDurationSchedule = (item) => {
47
+ var _a, _b;
48
+ return !(item == null ? void 0 : item.duration) && !((_a = item == null ? void 0 : item.schedules) == null ? void 0 : _a.length) && !((_b = item == null ? void 0 : item["schedule.ids"]) == null ? void 0 : _b.length);
49
+ };
50
+ var isAllNormalProduct = (items) => {
51
+ return items.every((item) => isNormalProductByDurationSchedule(item));
52
+ };
41
53
  var getDiscountAmount = (discount, total, price) => {
42
54
  var _a;
43
55
  if (discount.tag === "good_pass") {
@@ -49,8 +61,168 @@ var getDiscountAmount = (discount, total, price) => {
49
61
  }
50
62
  return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
51
63
  };
64
+ var getDateIsInSchedule = (dateTime, scheduleList) => {
65
+ if (!dateTime || !scheduleList || scheduleList.length === 0) {
66
+ return false;
67
+ }
68
+ const targetDate = (0, import_dayjs.default)(dateTime);
69
+ if (!targetDate.isValid()) {
70
+ return false;
71
+ }
72
+ for (const schedule of scheduleList) {
73
+ if (isTimeInScheduleItem(dateTime, schedule)) {
74
+ return true;
75
+ }
76
+ }
77
+ return false;
78
+ };
79
+ var isTimeInScheduleItem = (dateTime, schedule) => {
80
+ const targetDate = (0, import_dayjs.default)(dateTime);
81
+ const targetDateString = dateTime.split(" ")[0];
82
+ const targetTimeString = dateTime.split(" ")[1] || "00:00:00";
83
+ switch (schedule.type) {
84
+ case "standard":
85
+ return isInStandardSchedule(targetDate, targetDateString, targetTimeString, schedule);
86
+ case "time-slots":
87
+ return isInTimeSlotsSchedule(targetDate, targetDateString, targetTimeString, schedule);
88
+ case "designation":
89
+ return isInDesignationSchedule(targetDate, targetDateString, targetTimeString, schedule);
90
+ default:
91
+ return false;
92
+ }
93
+ };
94
+ var isInStandardSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
95
+ if (!schedule.start_time || !schedule.end_time) {
96
+ return false;
97
+ }
98
+ const startDate = (0, import_dayjs.default)(schedule.start_time);
99
+ const endDate = (0, import_dayjs.default)(schedule.end_time);
100
+ const isInBasicRange = targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate);
101
+ if (schedule.repeat_type === "none") {
102
+ return isInBasicRange;
103
+ }
104
+ return isInRepeatingSchedule(targetDate, targetDateString, targetTimeString, schedule, startDate, endDate);
105
+ };
106
+ var isInTimeSlotsSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
107
+ if (!schedule.start_time) {
108
+ return false;
109
+ }
110
+ const scheduleDate = schedule.start_time.split(" ")[0];
111
+ if (targetDateString !== scheduleDate) {
112
+ return false;
113
+ }
114
+ for (const timeSlot of schedule.time_slot) {
115
+ const slotStart = `${scheduleDate} ${timeSlot.start_time}:00`;
116
+ const slotEnd = `${scheduleDate} ${timeSlot.end_time}:00`;
117
+ const slotStartDate = (0, import_dayjs.default)(slotStart);
118
+ const slotEndDate = (0, import_dayjs.default)(slotEnd);
119
+ if (targetDate.isSameOrAfter(slotStartDate) && targetDate.isSameOrBefore(slotEndDate)) {
120
+ return true;
121
+ }
122
+ }
123
+ return false;
124
+ };
125
+ var isInDesignationSchedule = (targetDate, targetDateString, targetTimeString, schedule) => {
126
+ if (!schedule.designation) {
127
+ return false;
128
+ }
129
+ for (const designation of schedule.designation) {
130
+ const startDateTime = `${designation.start_date} ${designation.start_time}:00`;
131
+ const endDateTime = `${designation.end_date} ${designation.end_time}:00`;
132
+ const startDate = (0, import_dayjs.default)(startDateTime);
133
+ const endDate = (0, import_dayjs.default)(endDateTime);
134
+ if (targetDate.isSameOrAfter(startDate) && targetDate.isSameOrBefore(endDate)) {
135
+ return true;
136
+ }
137
+ }
138
+ return false;
139
+ };
140
+ var isInRepeatingSchedule = (targetDate, targetDateString, targetTimeString, schedule, startDate, endDate) => {
141
+ if (!schedule.repeat_rule) {
142
+ return false;
143
+ }
144
+ const { repeat_rule, repeat_type } = schedule;
145
+ const targetDateOnly = (0, import_dayjs.default)(targetDateString);
146
+ if (repeat_rule.included_date && repeat_rule.included_date.length > 0) {
147
+ for (const includedDate of repeat_rule.included_date) {
148
+ const includeStartDate = (0, import_dayjs.default)(includedDate.start);
149
+ const includeEndDate = (0, import_dayjs.default)(includedDate.end);
150
+ if (targetDateOnly.isSameOrAfter(includeStartDate, "day") && targetDateOnly.isSameOrBefore(includeEndDate, "day")) {
151
+ return true;
152
+ }
153
+ }
154
+ }
155
+ for (const excludedDate of repeat_rule.excluded_date) {
156
+ const excludeStartDate = (0, import_dayjs.default)(excludedDate.start);
157
+ const excludeEndDate = (0, import_dayjs.default)(excludedDate.end);
158
+ if (targetDateOnly.isSameOrAfter(excludeStartDate, "day") && targetDateOnly.isSameOrBefore(excludeEndDate, "day")) {
159
+ return false;
160
+ }
161
+ }
162
+ if (repeat_rule.end.type === "date" && repeat_rule.end.end_date) {
163
+ const ruleEndDate = (0, import_dayjs.default)(repeat_rule.end.end_date);
164
+ if (targetDate.isAfter(ruleEndDate)) {
165
+ return false;
166
+ }
167
+ }
168
+ switch (repeat_type) {
169
+ case "daily":
170
+ return isInDailyRepeat(targetDate, startDate, endDate, repeat_rule);
171
+ case "weekly":
172
+ return isInWeeklyRepeat(targetDate, startDate, endDate, repeat_rule);
173
+ default:
174
+ return false;
175
+ }
176
+ };
177
+ var isInDailyRepeat = (targetDate, startDate, endDate, repeatRule) => {
178
+ const daysDiff = targetDate.diff(startDate, "day");
179
+ if (daysDiff < 0) {
180
+ return false;
181
+ }
182
+ if (daysDiff % repeatRule.frequency !== 0) {
183
+ return false;
184
+ }
185
+ const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
186
+ const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
187
+ const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
188
+ return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
189
+ };
190
+ var isInWeeklyRepeat = (targetDate, startDate, endDate, repeatRule) => {
191
+ const targetDayOfWeek = targetDate.day();
192
+ if (!repeatRule.frequency_date.includes(targetDayOfWeek)) {
193
+ return false;
194
+ }
195
+ const weeksDiff = targetDate.diff(startDate, "week");
196
+ if (weeksDiff < 0) {
197
+ return false;
198
+ }
199
+ if (weeksDiff % repeatRule.frequency !== 0) {
200
+ return false;
201
+ }
202
+ const targetTimeOfDay = targetDate.hour() * 3600 + targetDate.minute() * 60 + targetDate.second();
203
+ const startTimeOfDay = startDate.hour() * 3600 + startDate.minute() * 60 + startDate.second();
204
+ const endTimeOfDay = endDate.hour() * 3600 + endDate.minute() * 60 + endDate.second();
205
+ return targetTimeOfDay >= startTimeOfDay && targetTimeOfDay <= endTimeOfDay;
206
+ };
207
+ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
208
+ if (!bookingTime) {
209
+ return discountList;
210
+ }
211
+ return discountList.filter((discount) => {
212
+ var _a, _b, _c;
213
+ debugger;
214
+ if (!((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.validity_type) || ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.validity_type) === "fixed_validity") {
215
+ return true;
216
+ }
217
+ return getDateIsInSchedule(bookingTime, ((_c = discount.custom_schedule_snapshot) == null ? void 0 : _c.data) || []);
218
+ });
219
+ };
52
220
  // Annotate the CommonJS export names for ESM import in node:
53
221
  0 && (module.exports = {
222
+ filterDiscountListByBookingTime,
223
+ getDateIsInSchedule,
54
224
  getDiscountAmount,
225
+ isAllNormalProduct,
226
+ isNormalProductByDurationSchedule,
55
227
  uniqueById
56
228
  });
@@ -27,7 +27,7 @@ export interface ModuleOptions {
27
27
  initialState?: Record<string, any>;
28
28
  otherParams?: Record<string, any>;
29
29
  }
30
- export type EventHandler = (data?: any) => void;
30
+ export declare type EventHandler = (data?: any) => void;
31
31
  export interface PisellCore {
32
32
  registerPlugin: (plugin: Plugin, options?: PluginOptions) => void;
33
33
  getPlugin: <T extends Plugin>(name: string) => T | null;
@@ -1,5 +1,5 @@
1
- type Action = (...args: any[]) => Promise<any>;
2
- type Task = {
1
+ declare type Action = (...args: any[]) => Promise<any>;
2
+ declare type Task = {
3
3
  uuid: string;
4
4
  type: string;
5
5
  actionParams?: Record<string, any>;
package/lib/utils/task.js CHANGED
@@ -23,10 +23,10 @@ __export(task_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(task_exports);
25
25
  var Tasks = class {
26
+ actions = /* @__PURE__ */ new Map();
27
+ taskQueue = [];
28
+ isRunning = false;
26
29
  constructor(actions) {
27
- this.actions = /* @__PURE__ */ new Map();
28
- this.taskQueue = [];
29
- this.isRunning = false;
30
30
  if (actions) {
31
31
  this.actions = actions;
32
32
  }
@@ -2,8 +2,8 @@
2
2
  * 监听模块
3
3
  *
4
4
  */
5
- export type WatchEventCallback = (...args: any[]) => void;
6
- export type WatchEventItem = {
5
+ export declare type WatchEventCallback = (...args: any[]) => void;
6
+ export declare type WatchEventItem = {
7
7
  key: string;
8
8
  callback: WatchEventCallback;
9
9
  };
@@ -23,12 +23,10 @@ __export(watch_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(watch_exports);
25
25
  var Watch = class {
26
- constructor() {
27
- // 监听列表
28
- this.events = /* @__PURE__ */ new Map();
29
- // 启用列表 - 使用数组保持顺序
30
- this.enableListMap = /* @__PURE__ */ new Map();
31
- }
26
+ // 监听列表
27
+ events = /* @__PURE__ */ new Map();
28
+ // 启用列表 - 使用数组保持顺序
29
+ enableListMap = /* @__PURE__ */ new Map();
32
30
  /**
33
31
  * 订阅事件
34
32
  * @param event 事件名称
@@ -132,7 +130,7 @@ var Watch = class {
132
130
  try {
133
131
  (_a = callbacks.get(lastCallbackKey)) == null ? void 0 : _a(...args);
134
132
  } catch (error) {
135
- console.error(`执行事件"${watchKey}"的回调时出错:`, error);
133
+ console.error(`\u6267\u884C\u4E8B\u4EF6"${watchKey}"\u7684\u56DE\u8C03\u65F6\u51FA\u9519:`, error);
136
134
  }
137
135
  }
138
136
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.320",
4
+ "version": "0.0.324",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",