@pisell/pisellos 0.0.252 → 0.0.253
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.
- package/dist/modules/Order/index.d.ts +13 -0
- package/dist/modules/Order/index.js +130 -15
- package/dist/solution/Checkout/index.d.ts +17 -38
- package/dist/solution/Checkout/index.js +947 -836
- package/dist/solution/Checkout/utils/index.d.ts +45 -1
- package/dist/solution/Checkout/utils/index.js +179 -1
- package/lib/modules/Order/index.d.ts +13 -0
- package/lib/modules/Order/index.js +108 -9
- package/lib/solution/Checkout/index.d.ts +17 -38
- package/lib/solution/Checkout/index.js +291 -214
- package/lib/solution/Checkout/utils/index.d.ts +45 -1
- package/lib/solution/Checkout/utils/index.js +139 -2
- package/package.json +1 -1
|
@@ -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
|
-
|
|
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
|
|
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$
|
|
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$
|
|
184
|
-
relationProductsCount: ((_params$
|
|
185
|
-
paymentsCount: ((_params$
|
|
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 =
|
|
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 =
|
|
344
|
+
_context3.next = 11;
|
|
230
345
|
return this.request.post('/order/checkout', orderData);
|
|
231
|
-
case
|
|
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
|
|
239
|
-
_context3.prev =
|
|
240
|
-
_context3.t0 = _context3["catch"](
|
|
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
|
|
358
|
+
case 20:
|
|
244
359
|
case "end":
|
|
245
360
|
return _context3.stop();
|
|
246
361
|
}
|
|
247
|
-
}, _callee3, this, [[
|
|
362
|
+
}, _callee3, this, [[2, 16]]);
|
|
248
363
|
}));
|
|
249
364
|
function createOrderByCheckout(_x4) {
|
|
250
365
|
return _createOrderByCheckout.apply(this, arguments);
|
|
@@ -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
|
|
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
|
*
|