@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
@@ -13,13 +13,35 @@ export declare class ProductsModule extends BaseModule implements Module {
13
13
  private store;
14
14
  private request;
15
15
  private dbManager;
16
+ private logger;
16
17
  private otherParams;
17
18
  private productsPriceCache;
18
19
  private readonly CACHE_MAX_DAYS;
19
20
  private formatters;
20
21
  private isPriceFormatterRegistered;
22
+ private productDataSource;
23
+ private pendingSyncMessages;
24
+ private syncTimer?;
21
25
  constructor(name?: string, version?: string);
22
26
  initialize(core: PisellCore, options: any): Promise<void>;
27
+ /**
28
+ * 记录信息日志
29
+ * @param title 日志标题
30
+ * @param metadata 日志元数据
31
+ */
32
+ private logInfo;
33
+ /**
34
+ * 记录警告日志
35
+ * @param title 日志标题
36
+ * @param metadata 日志元数据
37
+ */
38
+ private logWarning;
39
+ /**
40
+ * 记录错误日志
41
+ * @param title 日志标题
42
+ * @param metadata 日志元数据
43
+ */
44
+ private logError;
23
45
  /**
24
46
  * 加载商品价格(原始方法,不带缓存)
25
47
  * @private
@@ -31,14 +53,20 @@ export declare class ProductsModule extends BaseModule implements Module {
31
53
  * 缓存的是已经应用了价格的完整商品列表,避免重复转换
32
54
  * @param schedule_date 日期
33
55
  * @param extraContext 额外的上下文数据(可选,由 Server 层传入)
56
+ * @param options 可选参数
57
+ * @param options.changedIds 变更的商品 IDs,非空时仅对这些商品增量执行 prepare 并更新缓存
34
58
  * @returns 应用了价格的商品列表
35
59
  */
36
- getProductsWithPrice(schedule_date: string, extraContext?: Partial<ProductFormatterContext>): Promise<ProductData[]>;
60
+ getProductsWithPrice(schedule_date: string, extraContext?: Partial<ProductFormatterContext>, options?: {
61
+ changedIds?: number[];
62
+ }): Promise<ProductData[]>;
37
63
  /**
38
64
  * 准备带价格的商品数据(通过格式化器流程处理)
39
65
  * @param schedule_date 日期
40
66
  * @param extraContext 额外的上下文数据(可选)
41
- * @returns 完整处理后的商品列表
67
+ * @param options 可选参数
68
+ * @param options.productIds 指定商品 IDs,仅处理这些商品;不传则处理全量
69
+ * @returns 处理后的商品列表
42
70
  * @private
43
71
  */
44
72
  private prepareProductsWithPrice;
@@ -88,26 +116,52 @@ export declare class ProductsModule extends BaseModule implements Module {
88
116
  * 可用于手动刷新价格数据
89
117
  */
90
118
  clearPriceCache(): void;
119
+ /**
120
+ * 通过 ProductDataSource SSE 加载完整商品列表
121
+ */
122
+ loadProductsByServer(): Promise<any>;
123
+ /**
124
+ * 纯请求方法:通过 HTTP 接口获取商品列表(无副作用,不触发事件、不写 IndexDB)
125
+ * @param params 查询参数
126
+ * @returns 商品列表
127
+ */
128
+ private fetchProductsByHttp;
91
129
  /**
92
130
  * 加载完整商品列表通过接口(包含所有详细数据)
131
+ * 包含副作用:保存到 IndexDB + 触发 onProductsLoaded 事件
93
132
  * @param params 查询参数
94
133
  */
95
- loadProductsByServer(params?: {
134
+ loadProductsByServerHttp(params?: {
96
135
  category_ids?: number[];
97
136
  product_ids?: number[];
98
137
  collection?: number | string[];
99
138
  customer_id?: number;
100
139
  cacheId?: string;
101
- }): Promise<any>;
140
+ }): Promise<ProductData[]>;
102
141
  /**
103
- * 获取商品列表(从缓存)
142
+ * 获取商品列表(深拷贝,供外部安全使用)
104
143
  */
105
144
  getProducts(): Promise<ProductData[]>;
145
+ /**
146
+ * 内部获取商品列表的直接引用(无拷贝)
147
+ * 仅供内部 formatter 流程使用,因为 formatter 会创建新对象
148
+ */
149
+ private getProductsRef;
106
150
  /**
107
151
  * 根据ID获取单个商品(从内存缓存)
108
152
  * 使用 Map 快速查询,时间复杂度 O(1)
109
153
  */
110
154
  getProductById(id: number): Promise<ProductData | undefined>;
155
+ /**
156
+ * 根据 ID 列表删除商品(用于 pubsub 同步删除场景)
157
+ * 同时更新 store.list、store.map、IndexDB 和价格缓存
158
+ */
159
+ removeProductsByIds(ids: number[]): Promise<void>;
160
+ /**
161
+ * 重新从服务器加载全量商品列表并更新本地 store
162
+ * 用于 pubsub 同步 create / update / batch_update 场景
163
+ */
164
+ refreshProducts(): Promise<ProductData[]>;
111
165
  /**
112
166
  * 清空缓存
113
167
  */
@@ -133,6 +187,64 @@ export declare class ProductsModule extends BaseModule implements Module {
133
187
  * 在模块注册后自动调用
134
188
  */
135
189
  preload(): Promise<void>;
190
+ /**
191
+ * 初始化 ProductDataSource 实例
192
+ * 与 pubsub 订阅和数据获取分开,仅负责创建实例
193
+ */
194
+ private initProductDataSource;
195
+ /**
196
+ * 初始化 pubsub 订阅,监听管理后台商品变更
197
+ * 仅负责订阅 product / product_quotation 频道,消息通过防抖合并后批量处理
198
+ * 数据获取由 loadProductsByServer 单独负责
199
+ */
200
+ private setupProductSync;
201
+ /**
202
+ * 处理防抖后的同步消息批次
203
+ *
204
+ * product 模块:
205
+ * - operation === 'delete' → 本地删除
206
+ * - change_types 包含 price → 仅收集变更 IDs(不拉商品数据)
207
+ * - 有 body → body 完整数据直接覆盖本地
208
+ * - 其他 → SSE 增量拉取
209
+ *
210
+ * product_collection / product_category:
211
+ * - 按 relation_product_ids SSE 拉取受影响商品
212
+ *
213
+ * product_quotation:
214
+ * - 报价单变更影响范围大,直接清除价格缓存走全量重建
215
+ *
216
+ * 处理完成后 emit onProductsSyncCompleted(携带 changedIds),
217
+ * Server 层监听该事件后对变更商品增量执行 prepareProductsWithPrice 并更新缓存
218
+ */
219
+ private processProductSyncMessages;
220
+ /**
221
+ * 通过 SSE 按 ids 增量拉取商品数据
222
+ * 请求 GET /shop/core/stream?type=product&ids={ids}
223
+ */
224
+ private fetchProductsBySSE;
225
+ /**
226
+ * 将 body 完整数据直接覆盖到本地 store(不调用报价单接口)
227
+ * 已存在的 → 直接替换;不存在的 → 追加
228
+ * 同时更新 Map 缓存、IndexDB,触发 onProductsChanged
229
+ * 价格缓存由 processProductSyncMessages 末尾统一清除
230
+ */
231
+ private applyBodyUpdatesToStore;
232
+ /**
233
+ * 将增量拉取的商品合并到 store
234
+ * 已存在的 → 替换;新的 → 追加
235
+ * 同时更新 store.map、IndexDB,触发 onProductsChanged
236
+ */
237
+ private mergeProductsToStore;
238
+ /**
239
+ * 静默全量刷新:后台重新拉取全量 SSE 数据并更新本地
240
+ * 拿到完整数据后一次性替换 store,清除价格缓存,触发 onProductsSyncCompleted
241
+ * @returns 刷新后的商品列表
242
+ */
243
+ silentRefresh(): Promise<ProductData[]>;
244
+ /**
245
+ * 销毁同步资源(取消 pubsub 订阅、清除定时器)
246
+ */
247
+ destroyProductSync(): void;
136
248
  /**
137
249
  * 获取模块的路由定义
138
250
  * Products 模块暂不提供路由,由 Server 层统一处理