@pisell/pisellos 0.0.458 → 0.0.459

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.
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -358,7 +358,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
358
358
  };
359
359
  setOtherData(key: string, value: any): void;
360
360
  getOtherData(key: string): any;
361
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
361
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
362
362
  /**
363
363
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
364
364
  *
@@ -2215,6 +2215,7 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2215
2215
  // 计算容量的辅助函数
2216
2216
  var calculateCapacityFromCartItems = function calculateCapacityFromCartItems(items) {
2217
2217
  var _items$0$_resourceOri;
2218
+ if (items.length === 0) return 0;
2218
2219
  // 还需要增加一个判断,maxCapacity 必须是我单个人里选择的资源只有同一种的情况下才可以累加,否则单个账号都是 1
2219
2220
  var firstResource = (_items$0$_resourceOri = items[0]._resourceOrigin) === null || _items$0$_resourceOri === void 0 ? void 0 : _items$0$_resourceOri[0].id;
2220
2221
  var sameResourceLength = items.filter(function (item) {
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
@@ -1,386 +0,0 @@
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/model/strategy/adapter/promotion/index.ts
20
- var promotion_exports = {};
21
- __export(promotion_exports, {
22
- BUY_X_GET_Y_FREE_STRATEGY: () => BUY_X_GET_Y_FREE_STRATEGY,
23
- PromotionAdapter: () => PromotionAdapter,
24
- PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
25
- X_ITEMS_FOR_Y_PRICE_STRATEGY: () => X_ITEMS_FOR_Y_PRICE_STRATEGY,
26
- default: () => promotion_default
27
- });
28
- module.exports = __toCommonJS(promotion_exports);
29
- var import_type = require("./type");
30
- var import_evaluator = require("./evaluator");
31
- var PromotionAdapter = class {
32
- constructor() {
33
- this.name = "PromotionAdapter";
34
- this.version = "1.0.0";
35
- }
36
- /**
37
- * 准备运行时上下文
38
- *
39
- * 将业务数据转换为策略引擎可识别的 RuntimeContext
40
- */
41
- prepareContext(businessData) {
42
- const { products, currentProduct, channel, custom } = businessData;
43
- const now = /* @__PURE__ */ new Date();
44
- const currentDateTime = this.formatDateTime(now);
45
- const evaluatingProduct = currentProduct || (products.length > 0 ? products[0] : null);
46
- return {
47
- entities: {
48
- products,
49
- currentProduct: evaluatingProduct
50
- },
51
- attributes: {
52
- // 当前时间(格式化字符串,用于时间条件判断)
53
- currentDateTime,
54
- // 当前评估的商品信息(用于 product_match 运算符)
55
- productIdAndVariantId: evaluatingProduct ? {
56
- product_id: evaluatingProduct.product_id,
57
- product_variant_id: evaluatingProduct.product_variant_id
58
- } : null,
59
- // 渠道
60
- channel: channel || "",
61
- // 商品总数量
62
- totalQuantity: products.reduce((sum, p) => sum + p.quantity, 0),
63
- // 商品总金额
64
- totalAmount: products.reduce((sum, p) => sum + p.price * p.quantity, 0),
65
- // 自定义属性
66
- ...custom
67
- },
68
- metadata: {
69
- timestamp: Date.now()
70
- }
71
- };
72
- }
73
- /**
74
- * 转换执行结果
75
- *
76
- * 将策略引擎的通用结果转换为业务层需要的格式
77
- * 主要是整理 matchedActions,让业务层更容易使用
78
- */
79
- transformResult(result, businessData) {
80
- const applicableProducts = businessData ? this.getApplicableProducts(result, businessData) : [];
81
- if (!result.applicable) {
82
- return {
83
- isApplicable: false,
84
- applicableProducts: [],
85
- reason: result.message,
86
- reasonCode: result.code,
87
- strategyResult: result
88
- };
89
- }
90
- const matchedAction = result.matchedActions[0];
91
- if (!matchedAction) {
92
- return {
93
- isApplicable: false,
94
- applicableProducts: [],
95
- reason: "No matched action",
96
- reasonCode: "NO_ACTION",
97
- strategyResult: result
98
- };
99
- }
100
- const actionDetail = this.parseActionDetail(matchedAction);
101
- return {
102
- isApplicable: true,
103
- actionType: matchedAction.type,
104
- actionDetail,
105
- applicableProducts,
106
- strategyResult: result
107
- };
108
- }
109
- /**
110
- * 格式化配置
111
- */
112
- formatConfig(result, businessData) {
113
- return { result, businessData };
114
- }
115
- // ============================================
116
- // 私有辅助方法
117
- // ============================================
118
- /**
119
- * 格式化日期时间
120
- */
121
- formatDateTime(date) {
122
- const year = date.getFullYear();
123
- const month = String(date.getMonth() + 1).padStart(2, "0");
124
- const day = String(date.getDate()).padStart(2, "0");
125
- const hours = String(date.getHours()).padStart(2, "0");
126
- const minutes = String(date.getMinutes()).padStart(2, "0");
127
- const seconds = String(date.getSeconds()).padStart(2, "0");
128
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
129
- }
130
- /**
131
- * 解析 Action 详情
132
- *
133
- * 将 matchedAction 转换为更易用的结构
134
- */
135
- parseActionDetail(action) {
136
- switch (action.type) {
137
- case import_type.PROMOTION_ACTION_TYPES.X_ITEMS_FOR_Y_PRICE:
138
- return this.parseXItemsForYPriceAction(action);
139
- case import_type.PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE:
140
- return this.parseBuyXGetYFreeAction(action);
141
- default:
142
- return void 0;
143
- }
144
- }
145
- /**
146
- * 解析 X件Y元 Action
147
- */
148
- parseXItemsForYPriceAction(action) {
149
- const value = action.value || {};
150
- const config = action.config || {};
151
- return {
152
- type: import_type.PROMOTION_ACTION_TYPES.X_ITEMS_FOR_Y_PRICE,
153
- x: value.x || 2,
154
- price: value.price || 0,
155
- allowCrossProduct: config.allowCrossProduct ?? true,
156
- cumulative: config.cumulative ?? true
157
- };
158
- }
159
- /**
160
- * 解析 买X送Y Action
161
- */
162
- parseBuyXGetYFreeAction(action) {
163
- const value = action.value || {};
164
- const config = action.config || {};
165
- return {
166
- type: import_type.PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE,
167
- buyQuantity: value.buyQuantity || 1,
168
- freeQuantity: value.freeQuantity || 1,
169
- giftSelectionMode: config.giftSelectionMode || "user_select",
170
- cumulative: config.cumulative ?? true,
171
- giftProducts: config.giftProducts || []
172
- };
173
- }
174
- /**
175
- * 获取适用的商品列表
176
- *
177
- * 从购物车商品中筛选出符合策略条件的商品
178
- */
179
- getApplicableProducts(result, businessData) {
180
- const { products } = businessData;
181
- const productMatchRule = this.findProductMatchRule(result.config);
182
- if (!productMatchRule) {
183
- return products;
184
- }
185
- const configProducts = productMatchRule.value;
186
- return products.filter(
187
- (product) => this.isProductMatch(product, configProducts)
188
- );
189
- }
190
- /**
191
- * 查找商品匹配规则
192
- */
193
- findProductMatchRule(config) {
194
- var _a;
195
- if (!((_a = config == null ? void 0 : config.conditions) == null ? void 0 : _a.rules)) {
196
- return null;
197
- }
198
- return config.conditions.rules.find(
199
- (rule) => rule.field === "productIdAndVariantId" && (rule.operator === "product_match" || rule.operator === "object_in")
200
- );
201
- }
202
- /**
203
- * 检查商品是否匹配
204
- */
205
- isProductMatch(product, configProducts) {
206
- return configProducts.some((config) => {
207
- if (config.product_id !== product.product_id) {
208
- return false;
209
- }
210
- if (config.product_variant_id === 0) {
211
- return true;
212
- }
213
- return config.product_variant_id === product.product_variant_id;
214
- });
215
- }
216
- };
217
- var promotion_default = PromotionAdapter;
218
- var X_ITEMS_FOR_Y_PRICE_STRATEGY = {
219
- metadata: {
220
- id: "STRATEGY_001",
221
- name: {
222
- en: "2 items for $10",
223
- "zh-CN": "2杯10元",
224
- "zh-HK": "2杯10元"
225
- },
226
- type: "promotion",
227
- custom: {
228
- display: {
229
- product_card: {
230
- text: {
231
- en: "2 for $10",
232
- "zh-CN": "2杯10元",
233
- "zh-HK": "2杯10元"
234
- },
235
- type: "tag"
236
- }
237
- }
238
- }
239
- },
240
- conditions: {
241
- operator: "and",
242
- rules: [
243
- {
244
- type: "operator",
245
- field: "currentDateTime",
246
- value: "2023-01-01 00:00:00",
247
- operator: ">="
248
- },
249
- {
250
- type: "operator",
251
- field: "currentDateTime",
252
- value: "2027-01-01 00:00:00",
253
- operator: "<="
254
- },
255
- {
256
- type: "operator",
257
- field: "productIdAndVariantId",
258
- value: [
259
- {
260
- product_id: 60736,
261
- product_variant_id: 0
262
- // 0 = 匹配任意变体
263
- },
264
- {
265
- product_id: 60737,
266
- product_variant_id: 0
267
- // 0 = 匹配任意变体
268
- }
269
- ],
270
- operator: "product_match"
271
- }
272
- ],
273
- actionIds: ["1"]
274
- },
275
- actions: [
276
- {
277
- id: "1",
278
- type: "X_ITEMS_FOR_Y_PRICE",
279
- value: {
280
- x: 2,
281
- // 每X件
282
- price: 10
283
- // 固定价格Y元
284
- },
285
- valueType: "object",
286
- target: "product",
287
- priority: 1,
288
- config: {
289
- allowCrossProduct: true,
290
- // 允许跨商品组合(A+B可以凑成一组)
291
- cumulative: true
292
- // 可累计(买5件 = 2组优惠 + 1件原价)
293
- }
294
- }
295
- ]
296
- };
297
- var BUY_X_GET_Y_FREE_STRATEGY = {
298
- metadata: {
299
- id: "STRATEGY_002",
300
- name: {
301
- en: "Buy 1 Get 1 Free",
302
- "zh-CN": "买1送1",
303
- "zh-HK": "買1送1"
304
- },
305
- type: "promotion",
306
- custom: {
307
- display: {
308
- product_card: {
309
- text: {
310
- en: "Buy 1 Get 1",
311
- "zh-CN": "买1送1",
312
- "zh-HK": "買1送1"
313
- },
314
- type: "tag"
315
- }
316
- }
317
- }
318
- },
319
- conditions: {
320
- operator: "and",
321
- rules: [
322
- {
323
- type: "operator",
324
- field: "currentDateTime",
325
- value: "2023-01-01 00:00:00",
326
- operator: ">="
327
- },
328
- {
329
- type: "operator",
330
- field: "currentDateTime",
331
- value: "2027-01-01 00:00:00",
332
- operator: "<="
333
- },
334
- {
335
- type: "operator",
336
- field: "productIdAndVariantId",
337
- value: [
338
- {
339
- product_id: 60736,
340
- product_variant_id: 0
341
- // 0 = 匹配任意变体
342
- },
343
- {
344
- product_id: 60737,
345
- product_variant_id: 0
346
- // 0 = 匹配任意变体
347
- }
348
- ],
349
- operator: "product_match"
350
- }
351
- ],
352
- actionIds: ["1"]
353
- },
354
- actions: [
355
- {
356
- id: "1",
357
- type: "BUY_X_GET_Y_FREE",
358
- value: {
359
- buyQuantity: 1,
360
- // 买X件
361
- freeQuantity: 1
362
- // 送Y件
363
- },
364
- valueType: "object",
365
- target: "product",
366
- priority: 1,
367
- config: {
368
- // 可累计(买2送2、买3送3...)
369
- cumulative: true,
370
- // 可选的赠品列表
371
- giftProducts: [
372
- { product_id: 60757, product_variant_id: 0 },
373
- { product_id: 38782, product_variant_id: 0 },
374
- { product_id: 60749, product_variant_id: 27267 }
375
- ]
376
- }
377
- }
378
- ]
379
- };
380
- // Annotate the CommonJS export names for ESM import in node:
381
- 0 && (module.exports = {
382
- BUY_X_GET_Y_FREE_STRATEGY,
383
- PromotionAdapter,
384
- PromotionEvaluator,
385
- X_ITEMS_FOR_Y_PRICE_STRATEGY
386
- });
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 3 | 5 | 4 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;
@@ -358,7 +358,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
358
358
  };
359
359
  setOtherData(key: string, value: any): void;
360
360
  getOtherData(key: string): any;
361
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
361
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
362
362
  /**
363
363
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
364
364
  *
@@ -1535,6 +1535,8 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1535
1535
  }
1536
1536
  const calculateCapacityFromCartItems = (items) => {
1537
1537
  var _a2;
1538
+ if (items.length === 0)
1539
+ return 0;
1538
1540
  const firstResource = (_a2 = items[0]._resourceOrigin) == null ? void 0 : _a2[0].id;
1539
1541
  const sameResourceLength = items.filter((item) => {
1540
1542
  var _a3;
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.458",
4
+ "version": "0.0.459",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",