@pisell/pisellos 0.0.252 → 0.0.254

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.
@@ -7,8 +7,21 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
7
7
  protected defaultVersion: string;
8
8
  private store;
9
9
  private request;
10
+ private logger;
10
11
  constructor(name?: string, version?: string);
11
12
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
13
+ /**
14
+ * 记录信息日志
15
+ */
16
+ private logInfo;
17
+ /**
18
+ * 记录警告日志
19
+ */
20
+ private logWarning;
21
+ /**
22
+ * 记录错误日志
23
+ */
24
+ private logError;
12
25
  createOrder(params: CommitOrderParams['query']): {
13
26
  type: "virtual" | "appointment_booking";
14
27
  platform: string;
@@ -30,6 +30,8 @@ import dayjs from 'dayjs';
30
30
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
31
31
  _inherits(OrderModule, _BaseModule);
32
32
  var _super = _createSuper(OrderModule);
33
+ // LoggerManager 实例
34
+
33
35
  function OrderModule(name, version) {
34
36
  var _this;
35
37
  _classCallCheck(this, OrderModule);
@@ -38,6 +40,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
38
40
  _defineProperty(_assertThisInitialized(_this), "defaultVersion", '1.0.0');
39
41
  _defineProperty(_assertThisInitialized(_this), "store", void 0);
40
42
  _defineProperty(_assertThisInitialized(_this), "request", void 0);
43
+ _defineProperty(_assertThisInitialized(_this), "logger", void 0);
41
44
  return _this;
42
45
  }
43
46
  _createClass(OrderModule, [{
@@ -50,7 +53,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
50
53
  this.core = core;
51
54
  this.store = options.store;
52
55
  this.request = this.core.getPlugin('request');
53
- case 3:
56
+ this.logger = this.core.getPlugin('logger');
57
+ this.logInfo('OrderModule initialized successfully');
58
+ case 5:
54
59
  case "end":
55
60
  return _context.stop();
56
61
  }
@@ -61,6 +66,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
61
66
  }
62
67
  return initialize;
63
68
  }()
69
+ /**
70
+ * 记录信息日志
71
+ */
72
+ }, {
73
+ key: "logInfo",
74
+ value: function logInfo(title, metadata) {
75
+ if (this.logger) {
76
+ this.logger.addLog({
77
+ type: 'info',
78
+ title: "[OrderModule] ".concat(title),
79
+ metadata: metadata || {}
80
+ });
81
+ }
82
+ }
83
+
84
+ /**
85
+ * 记录警告日志
86
+ */
87
+ }, {
88
+ key: "logWarning",
89
+ value: function logWarning(title, metadata) {
90
+ if (this.logger) {
91
+ this.logger.addLog({
92
+ type: 'warning',
93
+ title: "[OrderModule] ".concat(title),
94
+ metadata: metadata || {}
95
+ });
96
+ }
97
+ }
98
+
99
+ /**
100
+ * 记录错误日志
101
+ */
102
+ }, {
103
+ key: "logError",
104
+ value: function logError(title, metadata) {
105
+ if (this.logger) {
106
+ this.logger.addLog({
107
+ type: 'error',
108
+ title: "[OrderModule] ".concat(title),
109
+ metadata: metadata || {}
110
+ });
111
+ }
112
+ }
64
113
  }, {
65
114
  key: "createOrder",
66
115
  value: function createOrder(params) {
@@ -120,6 +169,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
120
169
  }, {
121
170
  key: "checkBeforeSubmitOrder",
122
171
  value: function checkBeforeSubmitOrder(params) {
172
+ var _params$cartItems;
173
+ this.logInfo('checkBeforeSubmitOrder called', {
174
+ cartItemsCount: ((_params$cartItems = params.cartItems) === null || _params$cartItems === void 0 ? void 0 : _params$cartItems.length) || 0,
175
+ type: params.type
176
+ });
123
177
  var cartItems = params.cartItems,
124
178
  type = params.type;
125
179
  if (type === 'holder') {
@@ -137,15 +191,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
137
191
  key: "submitOrder",
138
192
  value: function () {
139
193
  var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(order) {
194
+ var _order$query$cartItem, _params$bookings, _params$relation_prod;
140
195
  var url, query, fetchUrl, params;
141
196
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
142
197
  while (1) switch (_context2.prev = _context2.next) {
143
198
  case 0:
199
+ this.logInfo('submitOrder called', {
200
+ url: order.url,
201
+ orderType: order.query.type,
202
+ platform: order.query.platform,
203
+ cartItemsCount: ((_order$query$cartItem = order.query.cartItems) === null || _order$query$cartItem === void 0 ? void 0 : _order$query$cartItem.length) || 0
204
+ });
144
205
  url = order.url, query = order.query;
145
206
  fetchUrl = url || '/order/appointment';
146
207
  params = this.createOrder(query);
208
+ this.logInfo('Calling backend order API', {
209
+ url: fetchUrl,
210
+ orderType: params.type,
211
+ platform: params.platform,
212
+ isDeposit: params.is_deposit,
213
+ bookingsCount: ((_params$bookings = params.bookings) === null || _params$bookings === void 0 ? void 0 : _params$bookings.length) || 0,
214
+ relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
215
+ scheduleDate: params.schedule_date
216
+ });
147
217
  return _context2.abrupt("return", this.request.post(fetchUrl, params));
148
- case 4:
218
+ case 6:
149
219
  case "end":
150
220
  return _context2.stop();
151
221
  }
@@ -170,21 +240,39 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
170
240
  key: "createOrderByCheckout",
171
241
  value: (function () {
172
242
  var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(params) {
173
- var _params$bookings, _params$relation_prod, _params$payments;
174
- var _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, _response$data, orderData, response;
243
+ var _params$bookings2, _params$relation_prod2, _params$payments, _params$payments2, _params$bookings3, _params$relation_prod3, _params$payments3;
244
+ var _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, _orderData$bookings2, _orderData$relation_p2, _orderData$payments4, _orderData$payments5, _response$data, orderData, response;
175
245
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
176
246
  while (1) switch (_context3.prev = _context3.next) {
177
247
  case 0:
248
+ this.logInfo('createOrderByCheckout called', {
249
+ type: params.type,
250
+ platform: params.platform,
251
+ is_deposit: params.is_deposit,
252
+ customer_id: params.customer_id,
253
+ bookingsCount: ((_params$bookings2 = params.bookings) === null || _params$bookings2 === void 0 ? void 0 : _params$bookings2.length) || 0,
254
+ relationProductsCount: ((_params$relation_prod2 = params.relation_products) === null || _params$relation_prod2 === void 0 ? void 0 : _params$relation_prod2.length) || 0,
255
+ paymentsCount: ((_params$payments = params.payments) === null || _params$payments === void 0 ? void 0 : _params$payments.length) || 0,
256
+ depositAmount: params.deposit_amount,
257
+ productTaxFee: params.product_tax_fee,
258
+ note: params.note,
259
+ scheduleDate: params.schedule_date,
260
+ hasOrderId: !!params.order_id,
261
+ orderIdIncluded: params.order_id,
262
+ paymentMethods: ((_params$payments2 = params.payments) === null || _params$payments2 === void 0 ? void 0 : _params$payments2.map(function (p) {
263
+ return p.code;
264
+ })) || []
265
+ });
178
266
  console.log('[Order] createOrderByCheckout 开始创建订单:', {
179
267
  type: params.type,
180
268
  platform: params.platform,
181
269
  is_deposit: params.is_deposit,
182
270
  customer_id: params.customer_id,
183
- bookingsCount: ((_params$bookings = params.bookings) === null || _params$bookings === void 0 ? void 0 : _params$bookings.length) || 0,
184
- relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
185
- paymentsCount: ((_params$payments = params.payments) === null || _params$payments === void 0 ? void 0 : _params$payments.length) || 0
271
+ bookingsCount: ((_params$bookings3 = params.bookings) === null || _params$bookings3 === void 0 ? void 0 : _params$bookings3.length) || 0,
272
+ relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
273
+ paymentsCount: ((_params$payments3 = params.payments) === null || _params$payments3 === void 0 ? void 0 : _params$payments3.length) || 0
186
274
  });
187
- _context3.prev = 1;
275
+ _context3.prev = 2;
188
276
  // 构建订单数据,设置默认值并允许 params 覆盖
189
277
  orderData = _objectSpread({
190
278
  sales_channel: 'my_pisel',
@@ -225,26 +313,53 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
225
313
  })) || []
226
314
  });
227
315
 
316
+ // 记录接口调用详情
317
+ this.logInfo('Calling backend checkout API', {
318
+ url: '/order/checkout',
319
+ orderType: orderData.type,
320
+ platform: orderData.platform,
321
+ isDeposit: orderData.is_deposit,
322
+ customerId: orderData.customer_id,
323
+ depositAmount: orderData.deposit_amount,
324
+ bookingsCount: ((_orderData$bookings2 = orderData.bookings) === null || _orderData$bookings2 === void 0 ? void 0 : _orderData$bookings2.length) || 0,
325
+ relationProductsCount: ((_orderData$relation_p2 = orderData.relation_products) === null || _orderData$relation_p2 === void 0 ? void 0 : _orderData$relation_p2.length) || 0,
326
+ paymentsCount: ((_orderData$payments4 = orderData.payments) === null || _orderData$payments4 === void 0 ? void 0 : _orderData$payments4.length) || 0,
327
+ paymentMethods: ((_orderData$payments5 = orderData.payments) === null || _orderData$payments5 === void 0 ? void 0 : _orderData$payments5.map(function (p) {
328
+ return {
329
+ code: p.code,
330
+ amount: p.amount,
331
+ type: p.type,
332
+ hasVoucherId: !!p.voucher_id,
333
+ orderPaymentType: p.order_payment_type
334
+ };
335
+ })) || [],
336
+ productTaxFee: orderData.product_tax_fee,
337
+ note: orderData.note,
338
+ scheduleDate: orderData.schedule_date,
339
+ hasOrderId: !!orderData.order_id,
340
+ smallTicketDataFlag: orderData.small_ticket_data_flag
341
+ });
342
+
228
343
  // 调用后端接口
229
- _context3.next = 9;
344
+ _context3.next = 11;
230
345
  return this.request.post('/order/checkout', orderData);
231
- case 9:
346
+ case 11:
232
347
  response = _context3.sent;
233
348
  console.log('[Order] 订单创建成功,后端响应:', {
234
349
  success: !!response,
235
350
  hasOrderId: !!(response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.order_id || response !== null && response !== void 0 && response.order_id)
236
351
  });
237
352
  return _context3.abrupt("return", response);
238
- case 14:
239
- _context3.prev = 14;
240
- _context3.t0 = _context3["catch"](1);
353
+ case 16:
354
+ _context3.prev = 16;
355
+ _context3.t0 = _context3["catch"](2);
241
356
  console.error('[Order] createOrderByCheckout 创建订单失败:', _context3.t0);
242
357
  throw _context3.t0;
243
- case 18:
358
+ case 20:
244
359
  case "end":
245
360
  return _context3.stop();
246
361
  }
247
- }, _callee3, this, [[1, 14]]);
362
+ }, _callee3, this, [[2, 16]]);
248
363
  }));
249
364
  function createOrderByCheckout(_x4) {
250
365
  return _createOrderByCheckout.apply(this, arguments);
@@ -116,23 +116,22 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
116
116
  while (1) switch (_context.prev = _context.next) {
117
117
  case 0:
118
118
  startTime = Date.now();
119
- if (!(Number((businessData === null || businessData === void 0 || (_businessData$amountI = businessData.amountInfo) === null || _businessData$amountI === void 0 ? void 0 : _businessData$amountI.totalAmount) || 0) <= 0 || Number((businessData === null || businessData === void 0 || (_businessData$amountI2 = businessData.amountInfo) === null || _businessData$amountI2 === void 0 ? void 0 : _businessData$amountI2.subTotal) || 0) <= 0)) {
120
- _context.next = 3;
119
+ walletParams = this.generateWalletParams(businessData);
120
+ if (!(Number((businessData === null || businessData === void 0 || (_businessData$amountI = businessData.amountInfo) === null || _businessData$amountI === void 0 ? void 0 : _businessData$amountI.totalAmount) || 0) < 0 || Number((businessData === null || businessData === void 0 || (_businessData$amountI2 = businessData.amountInfo) === null || _businessData$amountI2 === void 0 ? void 0 : _businessData$amountI2.subTotal) || 0) < 0)) {
121
+ _context.next = 4;
121
122
  break;
122
123
  }
123
124
  return _context.abrupt("return", {
124
125
  walletRecommendList: [],
125
126
  userIdentificationCodes: []
126
127
  });
127
- case 3:
128
+ case 4:
128
129
  // 发送初始化开始事件
129
130
  this.emitEvent(WalletPassHooks.OnWalletInitializationStarted, {
130
131
  businessData: businessData,
131
132
  startTime: startTime
132
133
  });
133
- _context.prev = 4;
134
- // 生成钱包API参数
135
- walletParams = this.generateWalletParams(businessData); // 调用标准的初始化流程
134
+ _context.prev = 5;
136
135
  _context.next = 8;
137
136
  return this.initializeWalletDataAsync(walletParams);
138
137
  case 8:
@@ -150,7 +149,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
150
149
  return _context.abrupt("return", result);
151
150
  case 16:
152
151
  _context.prev = 16;
153
- _context.t0 = _context["catch"](4);
152
+ _context.t0 = _context["catch"](5);
154
153
  _endTime = Date.now();
155
154
  _duration = _endTime - startTime; // 发送初始化失败事件
156
155
  this.emitEvent(WalletPassHooks.OnWalletInitializationFailed, {
@@ -166,7 +165,7 @@ export var WalletPassPaymentImpl = /*#__PURE__*/function () {
166
165
  case "end":
167
166
  return _context.stop();
168
167
  }
169
- }, _callee, this, [[4, 16]]);
168
+ }, _callee, this, [[5, 16]]);
170
169
  }));
171
170
  function initializeWalletDataFromBusinessAsync(_x) {
172
171
  return _initializeWalletDataFromBusinessAsync.apply(this, arguments);
@@ -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
  }
@@ -314,7 +314,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
314
314
  }[];
315
315
  setOtherData(key: string, value: any): void;
316
316
  getOtherData(key: string): any;
317
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
317
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
318
318
  /**
319
319
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
320
320
  *
@@ -111,7 +111,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
111
111
  * 获取当前的客户搜索条件
112
112
  * @returns 当前搜索条件
113
113
  */
114
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
114
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
115
115
  /**
116
116
  * 获取客户列表状态(包含滚动加载相关状态)
117
117
  * @returns 客户状态
@@ -18,10 +18,23 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
18
18
  private request;
19
19
  private store;
20
20
  private otherParams;
21
+ private logger;
21
22
  order: OrderModule;
22
23
  payment: PaymentModule;
23
24
  constructor(name?: string, version?: string);
24
25
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
26
+ /**
27
+ * 记录信息日志
28
+ */
29
+ private logInfo;
30
+ /**
31
+ * 记录警告日志
32
+ */
33
+ private logWarning;
34
+ /**
35
+ * 记录错误日志
36
+ */
37
+ private logError;
25
38
  /**
26
39
  * 初始化子模块
27
40
  */
@@ -366,33 +379,16 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
366
379
  * 验证结账参数
367
380
  */
368
381
  private validateCheckoutParams;
369
- /**
370
- * 验证本地订单数据
371
- */
372
- private validateLocalOrderData;
373
- /**
374
- * 生成本地订单ID
375
- */
376
- private generateLocalOrderId;
377
- /**
378
- * 格式化日期时间为 YYYY-MM-DD hh:mm:ss 格式
379
- *
380
- * @param date 要格式化的日期对象
381
- * @returns 格式化后的日期时间字符串
382
- */
383
- private formatDateTime;
384
- /**
385
- * 从购物车小计数据中提取金额信息
386
- */
387
- private extractAmountFromCartSummary;
388
382
  /**
389
383
  * 预加载支付方式(在初始化时调用)
390
384
  */
391
385
  private preloadPaymentMethods;
392
386
  /**
393
- * 计算总金额
387
+ * 清理过期的已同步订单数据
388
+ *
389
+ * 删除本地 IndexDB 中超过指定天数且已同步到后端的订单数据
394
390
  */
395
- private calculateTotalAmount;
391
+ private cleanupExpiredOrdersAsync;
396
392
  /**
397
393
  * 计算已支付金额(从 Payment 模块获取最新数据)
398
394
  */
@@ -415,28 +411,11 @@ export declare class CheckoutImpl extends BaseModule implements Module, Checkout
415
411
  * 当剩余待付款金额 <= 0 时,触发订单支付完成事件
416
412
  */
417
413
  private checkOrderPaymentCompletion;
418
- /**
419
- * 判断支付方式是否需要同步订单到后端
420
- *
421
- * 现金支付(CASHMANUAL)和自定义支付不需要同步,其他支付方式需要同步
422
- *
423
- * @param paymentCode 支付方式代码
424
- * @param paymentType 支付方式类型
425
- * @returns 是否需要同步订单
426
- */
427
- private shouldSyncOrderForPayment;
428
414
  /**
429
415
  * 同步订单到后端
430
416
  *
431
417
  * 调用后端 /order/checkout 接口创建真实订单
432
418
  */
433
- /**
434
- * 判断订单ID是否为本地生成的虚拟ID
435
- *
436
- * @param orderId 订单ID
437
- * @returns true 表示是虚拟ID,false 表示是真实的后端ID
438
- */
439
- private isVirtualOrderId;
440
419
  /**
441
420
  * 同步订单到后端并返回真实订单ID
442
421
  *