@pisell/pisellos 2.2.1 → 2.2.2

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.
@@ -131,6 +131,10 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
131
131
  return this.ensurePaymentTables();
132
132
  case 14:
133
133
  this.registerNetworkHandlers();
134
+
135
+ // // 预连接数据库
136
+ // this.dbManager.connect()
137
+
134
138
  console.log('[PaymentModule] 初始化完成');
135
139
  this.logInfo('PaymentModule initialized successfully');
136
140
  case 17:
@@ -657,7 +661,8 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
657
661
  key: "createPaymentOrderAsync",
658
662
  value: (function () {
659
663
  var _createPaymentOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(params) {
660
- var existingOrder, newOrder;
664
+ var _this3 = this;
665
+ var newOrder, dbAddStartTime, dbAddDuration;
661
666
  return _regeneratorRuntime().wrap(function _callee7$(_context7) {
662
667
  while (1) switch (_context7.prev = _context7.next) {
663
668
  case 0:
@@ -666,41 +671,41 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
666
671
  totalAmount: params.total_amount
667
672
  });
668
673
  _context7.prev = 1;
669
- _context7.next = 4;
670
- return this.dbManager.get('order', params.order_id);
671
- case 4:
672
- existingOrder = _context7.sent;
673
- this.logInfo('createPaymentOrderAsync existingOrder', {
674
- existingOrder: existingOrder
675
- });
674
+ // 检测是否有重复的 order_id
675
+ // console.time('createLocalOrderAsync: getExistingOrder')
676
+ // const existingOrder = await this.dbManager.get('order', params.order_id);
677
+ // const existingOrders = await this.dbManager.getAll('order');
676
678
  // const existingOrder = existingOrders.find(
677
679
  // (order: PaymentOrder) => String(order.id) === String(params.order_id),
678
680
  // );
679
- if (!existingOrder) {
680
- _context7.next = 20;
681
- break;
682
- }
683
- // 如果存在相同 order_id 的订单,更新该订单信息
684
- this.logInfo("createPaymentOrderAsync found duplicate order ID: ".concat(params.order_id, ", updating existing payment order"));
685
-
686
- // const originalOrder = { ...existingOrder };
687
- existingOrder.order_info = params.order_info;
688
- existingOrder.total_amount = params.total_amount;
689
- existingOrder.is_deposit = params.is_deposit || 0;
690
- existingOrder.deposit_amount = params.deposit_amount || '0.00';
691
-
692
- // 重新计算待付金额
693
- this.recalculateOrderAmount(existingOrder);
694
-
695
- // 更新到数据库
696
- _context7.next = 15;
697
- return this.dbManager.update('order', existingOrder);
698
- case 15:
699
- _context7.next = 17;
700
- return this.core.effects.emit("".concat(this.name, ":onOrderUpdated"), existingOrder);
701
- case 17:
702
- return _context7.abrupt("return", existingOrder);
703
- case 20:
681
+ // this.logInfo('createPaymentOrderAsync existingOrder', {
682
+ // existingOrder
683
+ // });
684
+ // console.timeEnd('createLocalOrderAsync: getExistingOrder')
685
+ // const existingOrder = existingOrders.find(
686
+ // (order: PaymentOrder) => String(order.id) === String(params.order_id),
687
+ // );
688
+ // if (existingOrder) {
689
+ // // 如果存在相同 order_id 的订单,更新该订单信息
690
+ // this.logInfo(
691
+ // `createPaymentOrderAsync found duplicate order ID: ${params.order_id}, updating existing payment order`,
692
+ // );
693
+ // // const originalOrder = { ...existingOrder };
694
+ // existingOrder.order_info = params.order_info;
695
+ // existingOrder.total_amount = params.total_amount;
696
+ // existingOrder.is_deposit = params.is_deposit || 0;
697
+ // existingOrder.deposit_amount = params.deposit_amount || '0.00';
698
+ // // 重新计算待付金额
699
+ // this.recalculateOrderAmount(existingOrder);
700
+ // // 更新到数据库
701
+ // await this.dbManager.update('order', existingOrder);
702
+ // // 触发更新事件
703
+ // this.core.effects.emit(
704
+ // `${this.name}:onOrderUpdated`,
705
+ // existingOrder,
706
+ // );
707
+ // return existingOrder;
708
+ // } else {
704
709
  // 创建新的支付订单
705
710
  newOrder = {
706
711
  uuid: getUniqueId('pay_order_'),
@@ -715,32 +720,37 @@ export var PaymentModule = /*#__PURE__*/function (_BaseModule) {
715
720
  tax_fee: '0.00',
716
721
  is_deposit: params.is_deposit || 0,
717
722
  deposit_amount: params.deposit_amount || '0.00'
718
- };
719
- _context7.next = 23;
723
+ }; // 🚀 性能监控:记录数据库添加操作耗时
724
+ dbAddStartTime = Date.now();
725
+ _context7.next = 6;
720
726
  return this.dbManager.add('order', newOrder);
721
- case 23:
722
- this.core.effects.emit("".concat(this.name, ":onOrderAdded"), newOrder);
723
- this.logInfo('createPaymentOrderAsync completed - new payment order created', {
727
+ case 6:
728
+ dbAddDuration = Date.now() - dbAddStartTime;
729
+ this.logInfo('Database add operation completed', {
730
+ operation: 'dbManager.add',
731
+ table: 'order',
724
732
  orderUuid: newOrder.uuid,
725
- orderId: newOrder.id
733
+ orderId: newOrder.order_id,
734
+ duration: "".concat(dbAddDuration, "ms"),
735
+ performance: dbAddDuration > 100 ? 'slow' : dbAddDuration > 50 ? 'medium' : 'fast'
726
736
  });
737
+ setTimeout(function () {
738
+ _this3.core.effects.emit("".concat(_this3.name, ":onOrderAdded"), newOrder);
739
+ }, 0);
727
740
  return _context7.abrupt("return", newOrder);
728
- case 26:
729
- _context7.next = 33;
730
- break;
731
- case 28:
732
- _context7.prev = 28;
741
+ case 12:
742
+ _context7.prev = 12;
733
743
  _context7.t0 = _context7["catch"](1);
734
744
  console.error('[PaymentModule] 创建支付订单失败', _context7.t0);
735
745
  this.logError('createPaymentOrderAsync failed', _context7.t0, {
736
746
  orderId: params.order_id
737
747
  });
738
748
  throw _context7.t0;
739
- case 33:
749
+ case 17:
740
750
  case "end":
741
751
  return _context7.stop();
742
752
  }
743
- }, _callee7, this, [[1, 28]]);
753
+ }, _callee7, this, [[1, 12]]);
744
754
  }));
745
755
  function createPaymentOrderAsync(_x6) {
746
756
  return _createPaymentOrderAsync.apply(this, arguments);
@@ -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
  /**
@@ -31,6 +31,17 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
31
31
  * RequestPlugin 接口定义
32
32
  */
33
33
 
34
+ export var RequestModeENUM = /*#__PURE__*/function (RequestModeENUM) {
35
+ RequestModeENUM["LOCAL"] = "local";
36
+ RequestModeENUM["REMOTE"] = "remote";
37
+ RequestModeENUM["LOCAL_REMOTE"] = "local_remote";
38
+ RequestModeENUM["REMOTE_LOCAL"] = "remote_local";
39
+ RequestModeENUM["OS_SERVER"] = "os_server";
40
+ return RequestModeENUM;
41
+ }({});
42
+
43
+ // 请求模式
44
+
34
45
  /**
35
46
  * 请求配置
36
47
  */
@@ -22,6 +22,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
22
22
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
23
  import { BaseModule } from "../../../modules/BaseModule";
24
24
  import { cloneDeep } from 'lodash-es';
25
+ import { RequestModeENUM } from "../../../plugins";
25
26
  import { ProductsHooks } from "./types";
26
27
  import { applyDetailValueToProducts, applyPriceDataToProducts } from "../../utils/product";
27
28
 
@@ -126,7 +127,12 @@ export var ProductsModule = /*#__PURE__*/function (_BaseModule) {
126
127
  customer_id: customer_id,
127
128
  schedule_date: schedule_date
128
129
  }, {
129
- useCache: true
130
+ useCache: true,
131
+ cache: {
132
+ mode: RequestModeENUM.REMOTE_LOCAL,
133
+ updateCache: true,
134
+ type: "indexDB"
135
+ }
130
136
  });
131
137
  case 3:
132
138
  productsData = _context2.sent;
@@ -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
  }