@pisell/pisellos 2.2.1 → 2.2.3

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.
@@ -323,48 +323,35 @@ var PaymentModule = class extends import_BaseModule.BaseModule {
323
323
  totalAmount: params.total_amount
324
324
  });
325
325
  try {
326
- const existingOrder = await this.dbManager.get("order", params.order_id);
327
- this.logInfo("createPaymentOrderAsync existingOrder", {
328
- existingOrder
326
+ const newOrder = {
327
+ uuid: (0, import_utils.getUniqueId)("pay_order_"),
328
+ id: params.order_id,
329
+ order_id: params.order_id,
330
+ order_info: params.order_info,
331
+ payment_status: import_types.PaymentStatus.Processing,
332
+ payment: [],
333
+ adjust_offline_payments: [],
334
+ total_amount: params.total_amount,
335
+ expect_amount: params.total_amount,
336
+ tax_fee: "0.00",
337
+ is_deposit: params.is_deposit || 0,
338
+ deposit_amount: params.deposit_amount || "0.00"
339
+ };
340
+ const dbAddStartTime = Date.now();
341
+ await this.dbManager.add("order", newOrder);
342
+ const dbAddDuration = Date.now() - dbAddStartTime;
343
+ this.logInfo("Database add operation completed", {
344
+ operation: "dbManager.add",
345
+ table: "order",
346
+ orderUuid: newOrder.uuid,
347
+ orderId: newOrder.order_id,
348
+ duration: `${dbAddDuration}ms`,
349
+ performance: dbAddDuration > 100 ? "slow" : dbAddDuration > 50 ? "medium" : "fast"
329
350
  });
330
- if (existingOrder) {
331
- this.logInfo(
332
- `createPaymentOrderAsync found duplicate order ID: ${params.order_id}, updating existing payment order`
333
- );
334
- existingOrder.order_info = params.order_info;
335
- existingOrder.total_amount = params.total_amount;
336
- existingOrder.is_deposit = params.is_deposit || 0;
337
- existingOrder.deposit_amount = params.deposit_amount || "0.00";
338
- this.recalculateOrderAmount(existingOrder);
339
- await this.dbManager.update("order", existingOrder);
340
- await this.core.effects.emit(
341
- `${this.name}:onOrderUpdated`,
342
- existingOrder
343
- );
344
- return existingOrder;
345
- } else {
346
- const newOrder = {
347
- uuid: (0, import_utils.getUniqueId)("pay_order_"),
348
- id: params.order_id,
349
- order_id: params.order_id,
350
- order_info: params.order_info,
351
- payment_status: import_types.PaymentStatus.Processing,
352
- payment: [],
353
- adjust_offline_payments: [],
354
- total_amount: params.total_amount,
355
- expect_amount: params.total_amount,
356
- tax_fee: "0.00",
357
- is_deposit: params.is_deposit || 0,
358
- deposit_amount: params.deposit_amount || "0.00"
359
- };
360
- await this.dbManager.add("order", newOrder);
351
+ setTimeout(() => {
361
352
  this.core.effects.emit(`${this.name}:onOrderAdded`, newOrder);
362
- this.logInfo("createPaymentOrderAsync completed - new payment order created", {
363
- orderUuid: newOrder.uuid,
364
- orderId: newOrder.id
365
- });
366
- return newOrder;
367
- }
353
+ }, 0);
354
+ return newOrder;
368
355
  } catch (error) {
369
356
  console.error("[PaymentModule] 创建支付订单失败", error);
370
357
  this.logError("createPaymentOrderAsync failed", error, {
@@ -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(): "normal" | "duration" | "session";
52
+ getProductType(): "duration" | "session" | "normal";
53
53
  }
@@ -35,6 +35,23 @@ export interface RequestPlugin extends Plugin {
35
35
  */
36
36
  request: <T = any>(options: RequestOptions) => Promise<T>;
37
37
  }
38
+ export declare enum RequestModeENUM {
39
+ LOCAL = "local",
40
+ REMOTE = "remote",
41
+ LOCAL_REMOTE = "local_remote",
42
+ REMOTE_LOCAL = "remote_local",
43
+ OS_SERVER = "os_server"
44
+ }
45
+ export type RequestModeType = RequestModeENUM.LOCAL | RequestModeENUM.REMOTE | RequestModeENUM.LOCAL_REMOTE | RequestModeENUM.REMOTE_LOCAL | RequestModeENUM.OS_SERVER;
46
+ export type CacheType = 'memory' | 'storage' | 'indexDB';
47
+ export interface CacheProps {
48
+ key?: string;
49
+ type?: CacheType;
50
+ updateCache?: boolean;
51
+ cacheUpdateChange?: (data: any) => void;
52
+ mode?: RequestModeType;
53
+ cacheKeyData?: any;
54
+ }
38
55
  /**
39
56
  * 请求配置
40
57
  */
@@ -49,6 +66,7 @@ export interface RequestOptions {
49
66
  responseType?: 'json' | 'text' | 'arraybuffer' | 'blob';
50
67
  withCredentials?: boolean;
51
68
  useCache?: boolean;
69
+ cache?: CacheProps;
52
70
  osServer?: boolean;
53
71
  }
54
72
  /**
@@ -20,9 +20,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  var request_exports = {};
21
21
  __export(request_exports, {
22
22
  RequestError: () => RequestError,
23
+ RequestModeENUM: () => RequestModeENUM,
23
24
  default: () => request_default
24
25
  });
25
26
  module.exports = __toCommonJS(request_exports);
27
+ var RequestModeENUM = /* @__PURE__ */ ((RequestModeENUM2) => {
28
+ RequestModeENUM2["LOCAL"] = "local";
29
+ RequestModeENUM2["REMOTE"] = "remote";
30
+ RequestModeENUM2["LOCAL_REMOTE"] = "local_remote";
31
+ RequestModeENUM2["REMOTE_LOCAL"] = "remote_local";
32
+ RequestModeENUM2["OS_SERVER"] = "os_server";
33
+ return RequestModeENUM2;
34
+ })(RequestModeENUM || {});
26
35
  var RequestError = class extends Error {
27
36
  constructor(message, config, request, response) {
28
37
  super(message);
@@ -314,5 +323,6 @@ var RequestPluginImpl = class {
314
323
  var request_default = new RequestPluginImpl();
315
324
  // Annotate the CommonJS export names for ESM import in node:
316
325
  0 && (module.exports = {
317
- RequestError
326
+ RequestError,
327
+ RequestModeENUM
318
328
  });
@@ -24,6 +24,7 @@ __export(products_exports, {
24
24
  module.exports = __toCommonJS(products_exports);
25
25
  var import_BaseModule = require("../../../modules/BaseModule");
26
26
  var import_lodash_es = require("lodash-es");
27
+ var import_plugins = require("../../../plugins");
27
28
  var import_types = require("./types");
28
29
  var import_product = require("../../utils/product");
29
30
  var INDEXDB_STORE_NAME = "products";
@@ -86,7 +87,13 @@ var ProductsModule = class extends import_BaseModule.BaseModule {
86
87
  customer_id,
87
88
  schedule_date
88
89
  },
89
- { useCache: true }
90
+ {
91
+ cache: {
92
+ mode: import_plugins.RequestModeENUM.REMOTE_LOCAL,
93
+ updateCache: true,
94
+ type: "indexDB"
95
+ }
96
+ }
90
97
  );
91
98
  return productsData.data;
92
99
  }
@@ -326,7 +326,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
326
326
  };
327
327
  setOtherData(key: string, value: any): void;
328
328
  getOtherData(key: string): any;
329
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
329
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
330
330
  /**
331
331
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
332
332
  *
@@ -19,6 +19,7 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
19
19
  private store;
20
20
  private otherParams;
21
21
  private logger;
22
+ private calculationCache;
22
23
  order: OrderModule;
23
24
  payment: PaymentModule;
24
25
  constructor(name?: string, version?: string);
@@ -302,16 +303,46 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
302
303
  * 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
303
304
  */
304
305
  private cleanupExpiredOrdersAsync;
306
+ /**
307
+ * 清除计算缓存
308
+ */
309
+ private clearCalculationCache;
310
+ /**
311
+ * 批量获取订单数据(用于性能优化)
312
+ * 一次性获取所有需要的数据,避免重复查询
313
+ */
314
+ private fetchOrderDataBatch;
315
+ /**
316
+ * 从支付项数组计算已支付金额(纯计算,不查询数据库)
317
+ */
318
+ private calculatePaidAmountFromItems;
305
319
  /**
306
320
  * 计算已支付金额(从 Payment 模块获取最新数据)
321
+ *
322
+ * 注意:此方法保持独立性,可以单独调用。
323
+ * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
307
324
  */
308
325
  private calculatePaidAmountAsync;
326
+ /**
327
+ * 从订单和支付项计算剩余金额(纯计算,不查询数据库)
328
+ */
329
+ private calculateRemainingAmountFromData;
330
+ /**
331
+ * 从订单和支付项计算剩余总金额(纯计算,排除定金)
332
+ */
333
+ private calculateRemainingTotalAmountFromData;
309
334
  /**
310
335
  * 计算剩余未支付金额(从 Payment 模块获取最新数据)
336
+ *
337
+ * 注意:此方法保持独立性,可以单独调用。
338
+ * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
311
339
  */
312
340
  private calculateRemainingAmountAsync;
313
341
  /**
314
342
  * 计算剩余未支付金额(排除定金计算,始终使用订单总金额)
343
+ *
344
+ * 注意:此方法保持独立性,可以单独调用。
345
+ * 在 updateStateAmountToRemaining 等批量操作中会使用缓存优化。
315
346
  */
316
347
  private calculateRemainingTotalAmountAsync;
317
348
  /**
@@ -320,12 +351,24 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
320
351
  private updateBalanceDueAmount;
321
352
  /**
322
353
  * 更新 stateAmount 为当前剩余未支付金额
354
+ *
355
+ * 优化版本:批量获取数据,避免重复查询数据库
323
356
  */
324
357
  private updateStateAmountToRemaining;
358
+ /**
359
+ * 检查订单支付是否完成(优化版,复用已获取的数据)
360
+ *
361
+ * @param paymentItems 已获取的支付项数据
362
+ * @param remainingAmount 已计算的剩余金额
363
+ */
364
+ private checkOrderPaymentCompletionOptimized;
325
365
  /**
326
366
  * 检查订单支付是否完成
327
367
  *
328
368
  * 当剩余待付款金额 <= 0 时,触发订单支付完成事件
369
+ *
370
+ * 注意:此方法保持独立性,可以单独调用。
371
+ * 在 updateStateAmountToRemaining 中会使用优化版本。
329
372
  */
330
373
  private checkOrderPaymentCompletion;
331
374
  /**
@@ -381,6 +424,8 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
381
424
  * 重置 store 状态
382
425
  *
383
426
  * 在创建新订单前调用,确保状态完全干净
427
+ *
428
+ * 🚀 性能优化:改为同步方法,事件发射不阻塞主流程
384
429
  */
385
- private resetStoreStateAsync;
430
+ private resetStoreState;
386
431
  }