@pisell/pisellos 0.0.479 → 0.0.481

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 (147) hide show
  1. package/dist/core/index.d.ts +3 -2
  2. package/dist/core/index.js +7 -0
  3. package/dist/effects/index.d.ts +2 -2
  4. package/dist/effects/index.js +34 -81
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/walletPass/type.d.ts +9 -2
  7. package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  8. package/dist/model/strategy/adapter/walletPass/utils.js +111 -72
  9. package/dist/modules/Customer/index.js +1 -1
  10. package/dist/modules/Discount/index.d.ts +6 -2
  11. package/dist/modules/Discount/index.js +14 -8
  12. package/dist/modules/Order/index.d.ts +1 -1
  13. package/dist/modules/Order/index.js +18 -13
  14. package/dist/modules/Payment/index.d.ts +4 -0
  15. package/dist/modules/Payment/index.js +774 -649
  16. package/dist/modules/Payment/walletpass.js +44 -17
  17. package/dist/modules/Product/index.d.ts +1 -1
  18. package/dist/modules/Product/types.d.ts +2 -0
  19. package/dist/modules/ProductList/index.d.ts +3 -0
  20. package/dist/modules/ProductList/index.js +9 -7
  21. package/dist/modules/Rules/index.d.ts +2 -2
  22. package/dist/modules/Rules/index.js +37 -31
  23. package/dist/modules/Rules/types.d.ts +2 -2
  24. package/dist/modules/Schedule/index.d.ts +9 -0
  25. package/dist/modules/Schedule/index.js +15 -2
  26. package/dist/plugins/app-types/app/app.d.ts +1 -0
  27. package/dist/plugins/request.d.ts +2 -0
  28. package/dist/server/index.d.ts +107 -2
  29. package/dist/server/index.js +1507 -279
  30. package/dist/server/modules/index.d.ts +6 -0
  31. package/dist/server/modules/index.js +7 -0
  32. package/dist/server/modules/menu/index.d.ts +19 -0
  33. package/dist/server/modules/menu/index.js +221 -71
  34. package/dist/server/modules/order/index.d.ts +87 -0
  35. package/dist/server/modules/order/index.js +916 -0
  36. package/dist/server/modules/order/types.d.ts +530 -0
  37. package/dist/server/modules/order/types.js +141 -0
  38. package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
  39. package/dist/server/modules/order/utils/filterBookings.js +350 -0
  40. package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
  41. package/dist/server/modules/order/utils/filterOrders.js +226 -0
  42. package/dist/server/modules/products/index.d.ts +117 -5
  43. package/dist/server/modules/products/index.js +1450 -240
  44. package/dist/server/modules/products/types.d.ts +25 -1
  45. package/dist/server/modules/products/types.js +3 -0
  46. package/dist/server/modules/resource/index.d.ts +86 -0
  47. package/dist/server/modules/resource/index.js +1128 -0
  48. package/dist/server/modules/resource/types.d.ts +121 -0
  49. package/dist/server/modules/resource/types.js +47 -0
  50. package/dist/server/modules/schedule/index.d.ts +19 -0
  51. package/dist/server/modules/schedule/index.js +229 -68
  52. package/dist/server/utils/product.d.ts +5 -0
  53. package/dist/server/utils/product.js +71 -31
  54. package/dist/solution/BookingTicket/index.d.ts +10 -2
  55. package/dist/solution/BookingTicket/index.js +41 -28
  56. package/dist/solution/BookingTicket/utils/scan/index.js +1 -1
  57. package/dist/solution/Checkout/index.d.ts +1 -0
  58. package/dist/solution/Checkout/index.js +286 -188
  59. package/dist/solution/Checkout/utils/index.d.ts +2 -1
  60. package/dist/solution/Checkout/utils/index.js +6 -4
  61. package/dist/solution/RegisterAndLogin/config.js +340 -1
  62. package/dist/solution/Sales/index.d.ts +96 -0
  63. package/dist/solution/Sales/index.js +566 -0
  64. package/dist/solution/Sales/types.d.ts +67 -0
  65. package/dist/solution/Sales/types.js +26 -0
  66. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  67. package/dist/solution/ShopDiscount/index.js +35 -22
  68. package/dist/solution/ShopDiscount/types.d.ts +6 -0
  69. package/dist/solution/ShopDiscount/utils.d.ts +9 -0
  70. package/dist/solution/ShopDiscount/utils.js +21 -27
  71. package/dist/solution/index.d.ts +2 -1
  72. package/dist/solution/index.js +2 -1
  73. package/dist/types/index.d.ts +5 -0
  74. package/lib/core/index.d.ts +3 -2
  75. package/lib/core/index.js +4 -0
  76. package/lib/effects/index.d.ts +2 -2
  77. package/lib/effects/index.js +22 -31
  78. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  79. package/lib/model/strategy/adapter/walletPass/type.d.ts +9 -2
  80. package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  81. package/lib/model/strategy/adapter/walletPass/utils.js +115 -48
  82. package/lib/modules/Customer/index.js +1 -1
  83. package/lib/modules/Discount/index.d.ts +6 -2
  84. package/lib/modules/Discount/index.js +3 -1
  85. package/lib/modules/Order/index.d.ts +1 -1
  86. package/lib/modules/Order/index.js +20 -18
  87. package/lib/modules/Payment/index.d.ts +4 -0
  88. package/lib/modules/Payment/index.js +134 -66
  89. package/lib/modules/Payment/walletpass.js +23 -4
  90. package/lib/modules/Product/index.d.ts +1 -1
  91. package/lib/modules/Product/types.d.ts +2 -0
  92. package/lib/modules/ProductList/index.d.ts +3 -0
  93. package/lib/modules/ProductList/index.js +2 -2
  94. package/lib/modules/Rules/index.d.ts +2 -2
  95. package/lib/modules/Rules/index.js +69 -73
  96. package/lib/modules/Rules/types.d.ts +2 -2
  97. package/lib/modules/Schedule/index.d.ts +9 -0
  98. package/lib/modules/Schedule/index.js +11 -0
  99. package/lib/plugins/app-types/app/app.d.ts +1 -0
  100. package/lib/plugins/request.d.ts +2 -0
  101. package/lib/server/index.d.ts +107 -2
  102. package/lib/server/index.js +773 -51
  103. package/lib/server/modules/index.d.ts +6 -0
  104. package/lib/server/modules/index.js +16 -2
  105. package/lib/server/modules/menu/index.d.ts +19 -0
  106. package/lib/server/modules/menu/index.js +121 -2
  107. package/lib/server/modules/order/index.d.ts +87 -0
  108. package/lib/server/modules/order/index.js +543 -0
  109. package/lib/server/modules/order/types.d.ts +530 -0
  110. package/lib/server/modules/order/types.js +34 -0
  111. package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
  112. package/lib/server/modules/order/utils/filterBookings.js +320 -0
  113. package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
  114. package/lib/server/modules/order/utils/filterOrders.js +197 -0
  115. package/lib/server/modules/products/index.d.ts +117 -5
  116. package/lib/server/modules/products/index.js +799 -62
  117. package/lib/server/modules/products/types.d.ts +25 -1
  118. package/lib/server/modules/products/types.js +1 -0
  119. package/lib/server/modules/resource/index.d.ts +86 -0
  120. package/lib/server/modules/resource/index.js +557 -0
  121. package/lib/server/modules/resource/types.d.ts +121 -0
  122. package/lib/server/modules/resource/types.js +35 -0
  123. package/lib/server/modules/schedule/index.d.ts +19 -0
  124. package/lib/server/modules/schedule/index.js +141 -12
  125. package/lib/server/utils/product.d.ts +5 -0
  126. package/lib/server/utils/product.js +56 -27
  127. package/lib/solution/BookingTicket/index.d.ts +10 -2
  128. package/lib/solution/BookingTicket/index.js +10 -2
  129. package/lib/solution/BookingTicket/utils/scan/index.js +0 -1
  130. package/lib/solution/Checkout/index.d.ts +1 -0
  131. package/lib/solution/Checkout/index.js +399 -331
  132. package/lib/solution/Checkout/utils/index.d.ts +2 -1
  133. package/lib/solution/Checkout/utils/index.js +6 -4
  134. package/lib/solution/RegisterAndLogin/config.js +266 -1
  135. package/lib/solution/Sales/index.d.ts +96 -0
  136. package/lib/solution/Sales/index.js +416 -0
  137. package/lib/solution/Sales/types.d.ts +67 -0
  138. package/lib/solution/Sales/types.js +35 -0
  139. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  140. package/lib/solution/ShopDiscount/index.js +14 -6
  141. package/lib/solution/ShopDiscount/types.d.ts +6 -0
  142. package/lib/solution/ShopDiscount/utils.d.ts +9 -0
  143. package/lib/solution/ShopDiscount/utils.js +6 -10
  144. package/lib/solution/index.d.ts +2 -1
  145. package/lib/solution/index.js +4 -2
  146. package/lib/types/index.d.ts +5 -0
  147. package/package.json +1 -1
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Resource 模块主键类型
3
+ */
4
+ export type ResourceId = number | string;
5
+ /**
6
+ * Sales / ScheduleEventResource:预约条目内关联资源(仅 ID 与占用,详情由设备端基准数据解析)
7
+ * @see 统一 Sales 数据协议 3.4.1 resources
8
+ */
9
+ export interface ScheduleEventResource {
10
+ /** 表单 ID。来源:ScheduleEventResource.form_id */
11
+ form_id: number;
12
+ /** 关联类型(如 form)。来源:ScheduleEventResource.relation_type */
13
+ relation_type: string;
14
+ /** 关联资源 ID(设备端用此 ID 从本地基准数据取资源详情)。来源:ScheduleEventResource.relation_id */
15
+ relation_id: number;
16
+ /** 占用容量。来源:ScheduleEventResource.capacity */
17
+ capacity: number;
18
+ /** 特殊状态。来源:ScheduleEventResource.like_status */
19
+ like_status?: string;
20
+ /** 资源元数据。来源:ScheduleEventResource.metadata */
21
+ metadata?: Record<string, unknown> | null;
22
+ /** 子资源(组合资源场景),结构同父级 */
23
+ children?: ScheduleEventResource[];
24
+ }
25
+ /**
26
+ * 资源预订数据结构
27
+ */
28
+ export interface ResourceBooking {
29
+ id: ResourceId;
30
+ resource_id?: ResourceId;
31
+ resourceId?: ResourceId;
32
+ user_id?: string | number;
33
+ userId?: string | number;
34
+ start_time?: string | number;
35
+ end_time?: string | number;
36
+ startTime?: string | number;
37
+ endTime?: string | number;
38
+ status?: string;
39
+ notes?: string;
40
+ metadata?: Record<string, any> | null;
41
+ [key: string]: any;
42
+ }
43
+ /**
44
+ * 资源数据结构(兼容历史数据)
45
+ */
46
+ export interface ResourceData {
47
+ id: ResourceId;
48
+ form_record_id?: ResourceId;
49
+ main_field?: string;
50
+ form_id?: number | string;
51
+ capacity?: number;
52
+ like_status?: 'common' | 'like';
53
+ type?: string;
54
+ resourceType?: string;
55
+ resource_form_id?: number | string | '';
56
+ schedule?: any[] | '';
57
+ times?: any;
58
+ metadata?: Record<string, any> | null;
59
+ children?: ResourceData[];
60
+ bookings?: ResourceBooking[];
61
+ [key: string]: any;
62
+ }
63
+ /**
64
+ * 查询选项
65
+ */
66
+ export interface QueryOptions {
67
+ includeBookings?: boolean;
68
+ [key: string]: any;
69
+ }
70
+ /**
71
+ * Resource 模块状态
72
+ */
73
+ export interface ResourceState {
74
+ /** 资源列表 */
75
+ list: ResourceData[];
76
+ /** 资源 Map 缓存(以 id 为 key,加速查询) */
77
+ map: Map<ResourceId, ResourceData>;
78
+ /** 预订列表 */
79
+ bookings: ResourceBooking[];
80
+ }
81
+ /**
82
+ * 与 ResourceDataSource 对齐的分页查询参数
83
+ */
84
+ export interface ResourcePageQuery {
85
+ 'ids[]'?: ResourceId[] | ResourceId;
86
+ ids?: ResourceId[];
87
+ num?: number | string;
88
+ skip?: number | string;
89
+ }
90
+ /**
91
+ * 与 ResourceDataSource 对齐的分页返回结构
92
+ */
93
+ export interface ResourcePageResult {
94
+ list: ResourceData[];
95
+ count: number;
96
+ skip: number;
97
+ size: number;
98
+ }
99
+ /**
100
+ * ResourceSyncMessage - pubsub 同步消息结构
101
+ */
102
+ export interface ResourceSyncMessage {
103
+ module?: string;
104
+ action?: string;
105
+ operation?: string;
106
+ id?: ResourceId;
107
+ ids?: ResourceId[];
108
+ body?: Partial<ResourceData>;
109
+ change_types?: string[];
110
+ relation_resource_ids?: ResourceId[];
111
+ _channelKey?: string;
112
+ }
113
+ /**
114
+ * Resource 模块钩子
115
+ */
116
+ export declare enum ResourceHooks {
117
+ onResourcesLoaded = "resource:onResourcesLoaded",
118
+ onResourcesChanged = "resource:onResourcesChanged",
119
+ onResourcesSyncCompleted = "resource:onResourcesSyncCompleted",
120
+ onBookingsChanged = "resource:onBookingsChanged"
121
+ }
@@ -0,0 +1,35 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/server/modules/resource/types.ts
20
+ var types_exports = {};
21
+ __export(types_exports, {
22
+ ResourceHooks: () => ResourceHooks
23
+ });
24
+ module.exports = __toCommonJS(types_exports);
25
+ var ResourceHooks = /* @__PURE__ */ ((ResourceHooks2) => {
26
+ ResourceHooks2["onResourcesLoaded"] = "resource:onResourcesLoaded";
27
+ ResourceHooks2["onResourcesChanged"] = "resource:onResourcesChanged";
28
+ ResourceHooks2["onResourcesSyncCompleted"] = "resource:onResourcesSyncCompleted";
29
+ ResourceHooks2["onBookingsChanged"] = "resource:onBookingsChanged";
30
+ return ResourceHooks2;
31
+ })(ResourceHooks || {});
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ ResourceHooks
35
+ });
@@ -11,7 +11,26 @@ export declare class ScheduleModuleEx extends BaseModule implements Module, Sche
11
11
  private request;
12
12
  private store;
13
13
  private dbManager;
14
+ private logger;
14
15
  constructor(name?: string, version?: string);
16
+ /**
17
+ * 记录信息日志
18
+ * @param title 日志标题
19
+ * @param metadata 日志元数据
20
+ */
21
+ private logInfo;
22
+ /**
23
+ * 记录警告日志
24
+ * @param title 日志标题
25
+ * @param metadata 日志元数据
26
+ */
27
+ private logWarning;
28
+ /**
29
+ * 记录错误日志
30
+ * @param title 日志标题
31
+ * @param metadata 日志元数据
32
+ */
33
+ private logError;
15
34
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
16
35
  /**
17
36
  * 加载当前店铺下所有 schedule(从服务器)
@@ -37,18 +37,69 @@ var import_BaseModule = require("../../../modules/BaseModule");
37
37
  var import_dayjs = __toESM(require("dayjs"));
38
38
  var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
39
39
  var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
40
- var import_utils = require("./utils");
40
+ var import_utils = require("../../../solution/ShopDiscount/utils");
41
41
  import_dayjs.default.extend(import_isSameOrBefore.default);
42
42
  import_dayjs.default.extend(import_isSameOrAfter.default);
43
43
  var INDEXDB_STORE_NAME = "schedule";
44
44
  var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
45
- // IndexDBManager 实例
45
+ // LoggerManager 实例
46
46
  constructor(name, version) {
47
47
  super(name, version);
48
48
  this.defaultName = "schedule";
49
49
  this.defaultVersion = "1.1.0";
50
50
  this.store = {};
51
51
  }
52
+ /**
53
+ * 记录信息日志
54
+ * @param title 日志标题
55
+ * @param metadata 日志元数据
56
+ */
57
+ logInfo(title, metadata) {
58
+ try {
59
+ if (this.logger) {
60
+ this.logger.addLog({
61
+ type: "info",
62
+ title: `[ScheduleModule] ${title}`,
63
+ metadata: metadata || {}
64
+ });
65
+ }
66
+ } catch {
67
+ }
68
+ }
69
+ /**
70
+ * 记录警告日志
71
+ * @param title 日志标题
72
+ * @param metadata 日志元数据
73
+ */
74
+ logWarning(title, metadata) {
75
+ try {
76
+ if (this.logger) {
77
+ this.logger.addLog({
78
+ type: "warning",
79
+ title: `[ScheduleModule] ${title}`,
80
+ metadata: metadata || {}
81
+ });
82
+ }
83
+ } catch {
84
+ }
85
+ }
86
+ /**
87
+ * 记录错误日志
88
+ * @param title 日志标题
89
+ * @param metadata 日志元数据
90
+ */
91
+ logError(title, metadata) {
92
+ try {
93
+ if (this.logger) {
94
+ this.logger.addLog({
95
+ type: "error",
96
+ title: `[ScheduleModule] ${title}`,
97
+ metadata: metadata || {}
98
+ });
99
+ }
100
+ } catch {
101
+ }
102
+ }
52
103
  async initialize(core, options) {
53
104
  this.core = core;
54
105
  this.request = core.getPlugin("request");
@@ -67,27 +118,50 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
67
118
  if (appPlugin) {
68
119
  const app = appPlugin.getApp();
69
120
  this.dbManager = app.dbManager;
121
+ this.logger = app.logger;
70
122
  if (this.dbManager) {
71
123
  console.log("[Schedule] IndexDB Manager 已初始化");
72
124
  } else {
73
125
  console.warn("[Schedule] IndexDB Manager 未找到");
74
126
  }
75
127
  }
128
+ this.logInfo("模块初始化完成", {
129
+ hasDbManager: !!this.dbManager,
130
+ hasLogger: !!this.logger,
131
+ initialScheduleCount: this.store.scheduleList.length
132
+ });
76
133
  }
77
134
  /**
78
135
  * 加载当前店铺下所有 schedule(从服务器)
79
136
  */
80
137
  async loadAllSchedule() {
81
138
  var _a;
82
- const scheduleList = await this.request.get(
83
- `/schedule`,
84
- { num: 999 },
85
- { useCache: true }
86
- );
87
- const list = ((_a = scheduleList.data) == null ? void 0 : _a.list) || [];
88
- await this.saveScheduleToIndexDB(list);
89
- this.setScheduleList(list);
90
- return list;
139
+ this.logInfo("开始从服务器加载日程列表");
140
+ const startTime = Date.now();
141
+ try {
142
+ const scheduleList = await this.request.get(
143
+ `/schedule`,
144
+ { num: 999 },
145
+ { cache: void 0 }
146
+ );
147
+ const list = ((_a = scheduleList.data) == null ? void 0 : _a.list) || [];
148
+ const duration = Date.now() - startTime;
149
+ this.logInfo("从服务器加载日程列表成功", {
150
+ scheduleCount: list.length,
151
+ duration: `${duration}ms`
152
+ });
153
+ await this.saveScheduleToIndexDB(list);
154
+ this.setScheduleList(list);
155
+ return list;
156
+ } catch (error) {
157
+ const duration = Date.now() - startTime;
158
+ const errorMessage = error instanceof Error ? error.message : String(error);
159
+ this.logError("从服务器加载日程列表失败", {
160
+ duration: `${duration}ms`,
161
+ error: errorMessage
162
+ });
163
+ throw error;
164
+ }
91
165
  }
92
166
  setScheduleList(list) {
93
167
  this.store.scheduleList = list;
@@ -105,6 +179,7 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
105
179
  */
106
180
  getScheduleByIds(ids) {
107
181
  if (!ids || ids.length === 0) {
182
+ this.logInfo("getScheduleByIds: 未提供有效的 ids", { idsCount: 0 });
108
183
  return [];
109
184
  }
110
185
  const result = [];
@@ -114,6 +189,11 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
114
189
  result.push(schedule);
115
190
  }
116
191
  }
192
+ this.logInfo("getScheduleByIds: 查询完成", {
193
+ requestedCount: ids.length,
194
+ foundCount: result.length,
195
+ notFoundCount: ids.length - result.length
196
+ });
117
197
  return result;
118
198
  }
119
199
  /**
@@ -132,16 +212,23 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
132
212
  * 清除缓存
133
213
  */
134
214
  async clear() {
215
+ this.logInfo("开始清空缓存", {
216
+ currentScheduleCount: this.store.scheduleList.length
217
+ });
135
218
  this.store.scheduleList = [];
136
219
  this.store.map.clear();
137
220
  if (this.dbManager) {
138
221
  try {
139
222
  await this.dbManager.clear(INDEXDB_STORE_NAME);
140
223
  console.log("[Schedule] IndexDB 缓存已清空");
224
+ this.logInfo("IndexDB 缓存已清空");
141
225
  } catch (error) {
226
+ const errorMessage = error instanceof Error ? error.message : String(error);
142
227
  console.error("[Schedule] 清空 IndexDB 缓存失败:", error);
228
+ this.logError("清空 IndexDB 缓存失败", { error: errorMessage });
143
229
  }
144
230
  }
231
+ this.logInfo("缓存清空完成");
145
232
  }
146
233
  /**
147
234
  * 判断日期是否在日程范围内
@@ -158,7 +245,13 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
158
245
  scheduleListData.push(item);
159
246
  }
160
247
  });
161
- return (0, import_utils.getDateIsInSchedule)(date, scheduleListData);
248
+ const result = (0, import_utils.getDateIsInSchedule)(date, scheduleListData);
249
+ this.logInfo("getDateIsInSchedule: 判断日期是否在日程范围内", {
250
+ date,
251
+ scheduleCount: scheduleListData.length,
252
+ isInSchedule: result
253
+ });
254
+ return result;
162
255
  }
163
256
  /**
164
257
  * 从 IndexDB 加载日程数据
@@ -166,13 +259,19 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
166
259
  */
167
260
  async loadScheduleFromIndexDB() {
168
261
  if (!this.dbManager) {
262
+ this.logWarning("loadScheduleFromIndexDB: dbManager 不可用");
169
263
  return [];
170
264
  }
171
265
  try {
172
266
  const scheduleList = await this.dbManager.getAll(INDEXDB_STORE_NAME);
267
+ this.logInfo("从 IndexDB 加载日程数据", {
268
+ scheduleCount: (scheduleList == null ? void 0 : scheduleList.length) ?? 0
269
+ });
173
270
  return scheduleList || [];
174
271
  } catch (error) {
272
+ const errorMessage = error instanceof Error ? error.message : String(error);
175
273
  console.error("[Schedule] 从 IndexDB 读取数据失败:", error);
274
+ this.logError("从 IndexDB 读取数据失败", { error: errorMessage });
176
275
  return [];
177
276
  }
178
277
  }
@@ -182,8 +281,10 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
182
281
  */
183
282
  async saveScheduleToIndexDB(scheduleList) {
184
283
  if (!this.dbManager) {
284
+ this.logWarning("saveScheduleToIndexDB: dbManager 不可用");
185
285
  return;
186
286
  }
287
+ this.logInfo("开始保存日程数据到 IndexDB", { scheduleCount: scheduleList.length });
187
288
  try {
188
289
  await this.dbManager.clear(INDEXDB_STORE_NAME);
189
290
  const savePromises = scheduleList.map(
@@ -193,8 +294,14 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
193
294
  console.log(
194
295
  `[Schedule] 已将 ${scheduleList.length} 条日程数据保存到 IndexDB`
195
296
  );
297
+ this.logInfo("日程数据已保存到 IndexDB", { scheduleCount: scheduleList.length });
196
298
  } catch (error) {
299
+ const errorMessage = error instanceof Error ? error.message : String(error);
197
300
  console.error("[Schedule] 保存数据到 IndexDB 失败:", error);
301
+ this.logError("保存数据到 IndexDB 失败", {
302
+ scheduleCount: scheduleList.length,
303
+ error: errorMessage
304
+ });
198
305
  }
199
306
  }
200
307
  /**
@@ -203,6 +310,8 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
203
310
  */
204
311
  async preload() {
205
312
  console.log("[Schedule] 开始预加载数据...");
313
+ const startTime = Date.now();
314
+ this.logInfo("开始预加载数据");
206
315
  try {
207
316
  const cachedData = await this.loadScheduleFromIndexDB();
208
317
  if (cachedData && cachedData.length > 0) {
@@ -211,17 +320,37 @@ var ScheduleModuleEx = class extends import_BaseModule.BaseModule {
211
320
  );
212
321
  this.store.scheduleList = (0, import_lodash_es.cloneDeep)(cachedData);
213
322
  this.syncScheduleMap();
323
+ const duration = Date.now() - startTime;
324
+ this.logInfo("预加载完成(从 IndexDB)", {
325
+ scheduleCount: cachedData.length,
326
+ duration: `${duration}ms`,
327
+ source: "IndexDB"
328
+ });
214
329
  return;
215
330
  }
216
331
  console.log("[Schedule] IndexDB 中没有缓存数据,从服务器加载...");
332
+ this.logInfo("IndexDB 中没有缓存数据,准备从服务器加载");
217
333
  } catch (error) {
334
+ const errorMessage = error instanceof Error ? error.message : String(error);
218
335
  console.warn("[Schedule] 从 IndexDB 加载数据失败:", error);
336
+ this.logWarning("从 IndexDB 加载数据失败,准备从服务器加载", { error: errorMessage });
219
337
  }
220
338
  const scheduleList = await this.loadAllSchedule();
221
339
  if (scheduleList && scheduleList.length > 0) {
222
340
  await this.saveScheduleToIndexDB(scheduleList);
223
341
  this.store.scheduleList = (0, import_lodash_es.cloneDeep)(scheduleList);
224
342
  this.syncScheduleMap();
343
+ const duration = Date.now() - startTime;
344
+ this.logInfo("预加载完成(从服务器)", {
345
+ scheduleCount: scheduleList.length,
346
+ duration: `${duration}ms`,
347
+ source: "Server"
348
+ });
349
+ } else {
350
+ const duration = Date.now() - startTime;
351
+ this.logWarning("预加载完成但未获取到数据", {
352
+ duration: `${duration}ms`
353
+ });
225
354
  }
226
355
  }
227
356
  };
@@ -1,5 +1,6 @@
1
1
  import { ProductData } from '../../modules/Product/types';
2
2
  import { FormattedProductData, LoadProductsPriceData, ProductFormatterContext } from '../modules/products/types';
3
+ export declare function perfMark(label: string, durationMs: number, meta?: Record<string, any>): void;
3
4
  /**
4
5
  * 将价格数据应用到商品列表(高性能版本)
5
6
  * 通过预构建 Map 索引,将时间复杂度从 O(n×m) 优化到 O(n+m)
@@ -9,6 +10,10 @@ import { FormattedProductData, LoadProductsPriceData, ProductFormatterContext }
9
10
  */
10
11
  export declare function applyPriceDataToProducts(products: ProductData[], priceData: LoadProductsPriceData[]): ProductData[];
11
12
  export declare const getIsSessionProduct: (product: ProductData) => boolean;
13
+ /**
14
+ * 根据 locale 将商品的 i18n 字段覆盖到对应原始字段
15
+ */
16
+ export declare function applyI18nToProducts(products: ProductData[], locale?: string): ProductData[];
12
17
  /**
13
18
  * 将详情值数据应用到商品列表
14
19
  * @param products 商品列表
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __export = (target, all) => {
8
6
  for (var name in all)
@@ -16,27 +14,31 @@ var __copyProps = (to, from, except, desc) => {
16
14
  }
17
15
  return to;
18
16
  };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
18
 
29
19
  // src/server/utils/product.ts
30
20
  var product_exports = {};
31
21
  __export(product_exports, {
32
22
  applyDetailValueToProducts: () => applyDetailValueToProducts,
23
+ applyI18nToProducts: () => applyI18nToProducts,
33
24
  applyPriceDataToProducts: () => applyPriceDataToProducts,
34
- getIsSessionProduct: () => getIsSessionProduct
25
+ getIsSessionProduct: () => getIsSessionProduct,
26
+ perfMark: () => perfMark
35
27
  });
36
28
  module.exports = __toCommonJS(product_exports);
37
- var import_decimal = __toESM(require("decimal.js"));
38
29
  var import_utils = require("../modules/schedule/utils");
39
30
  var import_utils2 = require("../../modules/Cart/utils");
31
+ function perfMark(label, durationMs, meta) {
32
+ try {
33
+ const w = typeof window !== "undefined" ? window : typeof globalThis !== "undefined" ? globalThis : null;
34
+ if (!w)
35
+ return;
36
+ if (!w.__PERF__)
37
+ w.__PERF__ = { records: [] };
38
+ w.__PERF__.records.push({ label, duration: Math.round(durationMs * 100) / 100, ts: Date.now(), ...meta });
39
+ } catch {
40
+ }
41
+ }
40
42
  function buildPriceIndexMap(priceData) {
41
43
  const priceMap = new Map(
42
44
  priceData.map((p) => [p.id, p])
@@ -53,7 +55,7 @@ function buildPriceIndexMap(priceData) {
53
55
  if (p.bundle_group && p.bundle_group.length > 0) {
54
56
  const groupMap = /* @__PURE__ */ new Map();
55
57
  p.bundle_group.forEach((bg) => {
56
- const itemMap = new Map(bg.bundle_item.map((bi) => [bi.id, bi]));
58
+ const itemMap = new Map((bg.bundle_item || []).map((bi) => [bi.id, bi]));
57
59
  groupMap.set(bg.id, itemMap);
58
60
  });
59
61
  bundleMap.set(p.id, groupMap);
@@ -62,14 +64,15 @@ function buildPriceIndexMap(priceData) {
62
64
  return { priceMap, variantMap, bundleMap };
63
65
  }
64
66
  function applyPriceDataToProducts(products, priceData) {
67
+ const t0 = performance.now();
65
68
  if (!priceData || priceData.length === 0) {
66
69
  console.log("[applyPriceDataToProducts] 没有价格数据,返回原商品");
67
70
  return products;
68
71
  }
72
+ const t1 = performance.now();
69
73
  const { priceMap, variantMap, bundleMap } = buildPriceIndexMap(priceData);
70
- console.log(
71
- `[applyPriceDataToProducts] 已构建价格索引,共 ${priceMap.size} 个商品价格`
72
- );
74
+ perfMark("buildPriceIndexMap", performance.now() - t1, { priceCount: priceData.length });
75
+ const t2 = performance.now();
73
76
  const updatedProducts = products.map((product) => {
74
77
  const priceInfo = priceMap.get(product.id);
75
78
  if (!priceInfo) {
@@ -94,10 +97,10 @@ function applyPriceDataToProducts(products, priceData) {
94
97
  });
95
98
  }
96
99
  }
97
- if (updatedProduct.bundle_groups && updatedProduct.bundle_groups.length > 0) {
100
+ if (updatedProduct.bundle_group && updatedProduct.bundle_group.length > 0) {
98
101
  const productBundleMap = bundleMap.get(product.id);
99
102
  if (productBundleMap) {
100
- updatedProduct.bundle_groups = updatedProduct.bundle_groups.map(
103
+ updatedProduct.bundle_group = updatedProduct.bundle_group.map(
101
104
  (bg) => {
102
105
  const groupItemMap = productBundleMap.get(bg.id);
103
106
  if (!groupItemMap)
@@ -108,9 +111,6 @@ function applyPriceDataToProducts(products, priceData) {
108
111
  const priceBi = groupItemMap.get(bi.id);
109
112
  if (priceBi) {
110
113
  let price = priceBi.price;
111
- if (priceBi.price_type === "markdown") {
112
- price = new import_decimal.default(price || 0).mul(-1).toNumber();
113
- }
114
114
  return {
115
115
  ...bi,
116
116
  price: String(price),
@@ -126,9 +126,11 @@ function applyPriceDataToProducts(products, priceData) {
126
126
  }
127
127
  return updatedProduct;
128
128
  });
129
- console.log(
130
- `[applyPriceDataToProducts] 已应用价格到 ${updatedProducts.length} 个商品`
131
- );
129
+ perfMark("applyPriceDataToProducts.mapProducts", performance.now() - t2, { count: products.length });
130
+ perfMark("applyPriceDataToProducts", performance.now() - t0, {
131
+ productCount: products.length,
132
+ priceCount: priceData.length
133
+ });
132
134
  return updatedProducts;
133
135
  }
134
136
  var getIsSessionProduct = (product) => {
@@ -154,6 +156,31 @@ var getIsOpenDetailModal = (product, context) => {
154
156
  scheduleTimeSlots
155
157
  };
156
158
  };
159
+ var I18N_FIELD_MAP = {
160
+ title_i18n: "title",
161
+ subtitle_i18n: "subtitle",
162
+ description_i18n: "description",
163
+ cover_i18n: "cover"
164
+ };
165
+ function applyI18nToProducts(products, locale) {
166
+ if (!locale)
167
+ return products;
168
+ return products.map((product) => {
169
+ let patched = null;
170
+ for (const [i18nKey, originalKey] of Object.entries(I18N_FIELD_MAP)) {
171
+ const i18nDict = product[i18nKey];
172
+ if (!i18nDict)
173
+ continue;
174
+ const localizedValue = i18nDict[locale];
175
+ if (localizedValue) {
176
+ if (!patched)
177
+ patched = { ...product };
178
+ patched[originalKey] = localizedValue;
179
+ }
180
+ }
181
+ return patched ?? product;
182
+ });
183
+ }
157
184
  var formatDataKey = (data) => {
158
185
  var _a, _b, _c, _d;
159
186
  const _data = {
@@ -235,6 +262,7 @@ var genCartDetailValue = (product, scheduleTimeSlots) => {
235
262
  return formatDataKey(params);
236
263
  };
237
264
  function applyDetailValueToProducts(products, context) {
265
+ const t0 = performance.now();
238
266
  const newProducts = products.map((product) => {
239
267
  const { isOpenDetailModal, scheduleTimeSlots } = getIsOpenDetailModal(
240
268
  product,
@@ -246,17 +274,18 @@ function applyDetailValueToProducts(products, context) {
246
274
  }
247
275
  return {
248
276
  ...product,
249
- // 是否打开详情弹窗
250
277
  isOpenDetailModal,
251
- // 购物车详情值
252
278
  cartDetailValue
253
279
  };
254
280
  });
281
+ perfMark("applyDetailValueToProducts", performance.now() - t0, { count: products.length });
255
282
  return newProducts;
256
283
  }
257
284
  // Annotate the CommonJS export names for ESM import in node:
258
285
  0 && (module.exports = {
259
286
  applyDetailValueToProducts,
287
+ applyI18nToProducts,
260
288
  applyPriceDataToProducts,
261
- getIsSessionProduct
289
+ getIsSessionProduct,
290
+ perfMark
262
291
  });
@@ -21,7 +21,15 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
21
21
  * @param params 包含 schedule_date 的参数
22
22
  * @returns 商品列表
23
23
  */
24
- loadProducts(params?: ILoadProductsParams): Promise<any>;
24
+ loadProducts(params?: ILoadProductsParams, options?: {
25
+ callback?: (result: any) => void;
26
+ subscriberId?: string;
27
+ }): Promise<any>;
28
+ /**
29
+ * 取消商品查询订阅
30
+ * @param subscriberId 订阅时传入的 subscriberId
31
+ */
32
+ unsubscribeProductQuery(subscriberId?: string): void;
25
33
  /**
26
34
  * 初始化外设扫码结果监听
27
35
  */
@@ -123,7 +131,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
131
  * 获取当前的客户搜索条件
124
132
  * @returns 当前搜索条件
125
133
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
134
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
127
135
  /**
128
136
  * 获取客户列表状态(包含滚动加载相关状态)
129
137
  * @returns 客户状态